Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
spring_suvarna
Posts: 330
Registered: ‎02-25-2009
My Device: Not Specified
Accepted Solution

word wrapping in labelfield

Hello,

 

i wanted to design a screen in which some text (paragraph) will be centered aligned with some space left from right as well as left side.

 

right now am using LabelField of width (Display.getWidth() -50) , but am not able to do it centered aligned with some space left from both the side.

i have used LAbelField.HCENTER also, but its not so helpful

 

the text int the label field has to be wrapped as width decreases.

 

does anyone have any knowledge about this.

 

thanks in advance

Developer
simon_hain
Posts: 16,364
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: word wrapping in labelfield

use a custom layout manager to put the field exactly where you want it.

see
http://www.blackberry.com/knowledgecenterpublic/livelink.exe/How_To_-_Create_a_custom_layout_manager...

as for the text: you'll have to cover this yourself, you can use getWidth and getAdvance for it.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
spring_suvarna
Posts: 330
Registered: ‎02-25-2009
My Device: Not Specified

Re: word wrapping in labelfield

here is an example how you can wrap the line in labelfield

 

your labelField is of width (Display.getWidth() - 50)

 

 

LabelField temp_label = new LabelField("", Field.USE_ALL_WIDTH | DrawStyle.LEFT) {
    public int getPreferredWidth() { 
        return Display.getWidth() - 50; 
    } 
                
    protected void layout(int maxWidth,int maxHeight) {
        super.layout(getPreferredWidth(),maxHeight);
        setExtent(getPreferredWidth(), getHeight());
    }
};
temp_label.setText("This is a long statement.");

 

try this out. It will work

 

Thanks.

 

Contributor
Krisper
Posts: 44
Registered: ‎07-15-2010
My Device: Not Specified

Re: word wrapping in labelfield

Sorry to post to an old topic but I used the advice here to get my label text to wrap over multiple lines.

 

I am new to the forums and to writing blackberry apps and have been doing lots of tutorials etc.

 

Anyway I have a custom LabelField. I have just changed it to wrap the text around, but this only works if I set the text using setText(); I am changing the colour of the text so I am overriding paint() and using graphics.drawText(text, 0, 0); to write the text. Doing this I no longer get the text wrapping around. How can I do both?

 

Thanks.

Developer
simon_hain
Posts: 16,364
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: word wrapping in labelfield

welcome to the support forums.

please use an own thread for your question (even when it's related) and don't post questions in solved threads.

to answer you nonetheless:

you can use setColor in the paint method and call super.paint, this will allow the field to do the rest of the work itself

----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Contributor
Krisper
Posts: 44
Registered: ‎07-15-2010
My Device: Not Specified

Re: word wrapping in labelfield

Sorry, and thanks for the solution.