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
arunbiet
Posts: 377
Registered: ‎06-22-2010
My Device: na
My Carrier: blackberry developer
Accepted Solution

how to repaint a text in a labelfield

I have a labelfield with text.I want that when i click a button,the labelfield text should change.I have tried with labelfield.settext method,but its not working,plz help

Please use plain text.
Developer
peter_strange
Posts: 19,601
Registered: ‎07-14-2008
My Device: Not Specified

Re: how to repaint a text in a labelfield

<LabelField>.setText method does change the text.  Debug the statement, I suspect it is throwing an Exception, probably because you are not invoking it on the Event Thread.  . 

Please use plain text.
Developer
arunbiet
Posts: 377
Registered: ‎06-22-2010
My Device: na
My Carrier: blackberry developer

Re: how to repaint a text in a labelfield

but how to delete the old text and put a a new text

Please use plain text.
Developer
peter_strange
Posts: 19,601
Registered: ‎07-14-2008
My Device: Not Specified

Re: how to repaint a text in a labelfield

if your LabelField is called lab and is on the screen, then

 

lab.setText("New Text").

 

will update the display with "New Text", assuming you run this on the Event Thread. 

Please use plain text.
Developer
arunbiet
Posts: 377
Registered: ‎06-22-2010
My Device: na
My Carrier: blackberry developer

Re: how to repaint a text in a labelfield

yes true,but if i use draw text in paint method and than use settext in the onnavigation click of button field,text is overlapping on the old text,how to delete the old text

Please use plain text.
Developer
arunbiet
Posts: 377
Registered: ‎06-22-2010
My Device: na
My Carrier: blackberry developer

Re: how to repaint a text in a labelfield

or else like drawtext is there any way to set postion in settext

Please use plain text.
Developer
peter_strange
Posts: 19,601
Registered: ‎07-14-2008
My Device: Not Specified

Re: how to repaint a text in a labelfield

Ah - I thought you were using a standard LabelField.  Might have been useful to mention that at the start.

 

If you really have to use drawText, then you should clear the area first.  There are a variety of ways you can do that, but probably the easiest is to just call paintBackground in your paint() method.

 

Otherwise you can set the color and use fillRect.  Review the Graphics API for more on these methods. 

 

Please use plain text.
Developer
arunbiet
Posts: 377
Registered: ‎06-22-2010
My Device: na
My Carrier: blackberry developer

Re: how to repaint a text in a labelfield

yes Peter i too hate using DrawText,but i dont have any option.Actually i need to position the text inside labelfield depending on alignment attribute value i am getting from an XMl,so suppose its CENTER,i am setting it at center in drawtext,anyways i will give ur solution a try and get back to u

Please use plain text.
Developer
arunbiet
Posts: 377
Registered: ‎06-22-2010
My Device: na
My Carrier: blackberry developer

Re: how to repaint a text in a labelfield

I am actually using g.clear(); coz super.paintbackground() doesnt clear the text

Please use plain text.
Developer
arunbiet
Posts: 377
Registered: ‎06-22-2010
My Device: na
My Carrier: blackberry developer

Re: how to repaint a text in a labelfield

but its going complete white,my backgroudn image is not vsisble once i do g.clear()

Please use plain text.