×

Discussion Board

Results 1 to 7 of 7

Hybrid View

  1. #1
    Registered User
    Join Date
    May 2013
    Posts
    20

    Using graphic to drawString in more line

    Hi, I am developing my app
    I want to using graphic to draw a String auto down the line when end of screen or display in exactly line i need ( such text wrap on in list)
    I have a class such:
    class TouchItem extends CustomItem
    {
    ....
    ....

    public TouchItem( String label, int itemsHeight, Main midlet)
    {
    ...
    ...
    }

    public void paint(Graphics g, int width, int height) {


    g.setColor(midlet.getForegroundColor());
    //g.drawRect(0, 0, width-2, height-2);
    g.drawString(label,(g.getFont().getSize()),
    (height - g.getFont().getHeight())/2, g.LEFT|g.TOP); //draw here


    }
    who anybody help me?
    Last edited by tieubinh; 2013-05-15 at 14:41.

  2. #2
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,737

    Re: Using graphic to drawString in more line


  3. #3
    Registered User
    Join Date
    May 2013
    Posts
    20

    Re: Using graphic to drawString in more line

    Thanks a lot, I have two classes
    One is a class LineEnumeration (Font font, String label, int width)
    Another one is:
    class TouchItem extends CustomItem
    {
    ....
    ....

    public TouchItem( String label, int itemsHeight, Main midlet)
    {
    ...
    ...
    }

    public void paint(Graphics g, int width, int height) {

    g.setColor(midlet.getForegroundColor());
    //g.drawRect(0, 0, width-2, height-2);
    // g.drawString(label,(g.getFont().getSize()),
    // (height - g.getFont().getHeight())/2, g.LEFT|g.TOP);
    LineEnumeration e = new LineEnumeration(g.getFont(), label, width);
    while ( e.hasMoreElements() ) {
    g.drawString(e.nextElement().toString(),g.getFont().getFace(),
    g.getFont().getHeight(), Graphics.TOP | Graphics.LEFT);//I draw string here
    height += 100;
    }
    }

    It display in several sessions but in the same line and overlap

  4. #4
    Nokia Developer Moderator
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    28,737

    Re: Using graphic to drawString in more line

    You are not using the variable 'height', that is why. Review the arguments of drawString.
    EDIT: ah, there is the solution already.
    Last edited by wizard_hu_; 2013-05-15 at 21:06.

  5. #5
    Registered User
    Join Date
    May 2013
    Posts
    20

    Re: Using graphic to drawString in more line

    I see, thanks so much
    Quote Originally Posted by wizard_hu_ View Post
    You are not using the variable 'height', that is why. Review the arguments of drawString.
    EDIT: ah, there is the solution already.

  6. #6
    Nokia Developer Champion
    Join Date
    Mar 2013
    Posts
    686

    Re: Using graphic to drawString in more line

    It seems that its because you pass wrong parameters to drawString method.....

    Your code shows
    "g.drawString(e.nextElement().toString(),g.getFont().getFace(),
    g.getFont().getHeight(), Graphics.TOP | Graphics.LEFT);//I draw string here"
    But the 2nd and 3rd parameter are ment to be the X and Y of the anchor of the string and you have them as Fixed values ....

    Try this instead
    int y = 1;
    while ( e.hasMoreElements() ) {
    g.drawString(e.nextElement().toString(),1,
    y, Graphics.TOP | Graphics.LEFT);//I draw string here
    y+= g.getFont().getHeight();
    }

  7. #7
    Registered User
    Join Date
    May 2013
    Posts
    20

    Re: Using graphic to drawString in more line

    Quote Originally Posted by shai.i View Post
    It seems that its because you pass wrong parameters to drawString method.....

    Your code shows
    "g.drawString(e.nextElement().toString(),g.getFont().getFace(),
    g.getFont().getHeight(), Graphics.TOP | Graphics.LEFT);//I draw string here"
    But the 2nd and 3rd parameter are ment to be the X and Y of the anchor of the string and you have them as Fixed values ....

    Try this instead
    int y = 1;
    while ( e.hasMoreElements() ) {
    g.drawString(e.nextElement().toString(),1,
    y, Graphics.TOP | Graphics.LEFT);//I draw string here
    y+= g.getFont().getHeight();
    }
    That's awesome, thanks a lot!

Similar Threads

  1. drawString() is defferent?
    By Vitaly_iva in forum Mobile Java General
    Replies: 0
    Last Post: 2008-02-15, 19:59
  2. listbox with small graphic vs. listbox with large graphic
    By huami in forum Symbian User Interface
    Replies: 4
    Last Post: 2007-08-07, 10:57
  3. g.drawString()
    By yafy in forum Mobile Java Tools & SDKs
    Replies: 3
    Last Post: 2006-05-12, 08:55
  4. g.drawString + Double
    By patricksteiner in forum Mobile Java General
    Replies: 4
    Last Post: 2003-03-26, 14:07
  5. DirectGraphics and drawString
    By mugent in forum Mobile Java General
    Replies: 1
    Last Post: 2003-02-17, 12:37

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×