Skip to main content

Label setText not chage the text

2 replies [Last post]
sawal_xp
Offline
Joined: 2008-02-12
Points: 0

hi..i got problem now in Label.

i working with some of thread..and many Label.
i was process incoming data from my web services server, and update it to labels..

some time, when data is incoming, and i update it to my label

-- label.setText(data.fromserver);

it's not update, or the text not change..

example :
String data from server -> msg= "123";

before update : label's text is set to -> label.setText("-");

after incoming message : label value to be -> label.setText(msg);

so that, in emulator, label value must be "123" ...but in emulator label value still in "-" ...

i really want to know, is the label update or not, show i do print to system.out...

System.out.println("value label = " + label.getText());

the result is -> value label = 123

so, the label in the object was updated but in emulator not display correctly...
why..?? may be need to be refresh(), repaint() or what..?

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
cinsulan
Offline
Joined: 2008-04-19
Points: 0

Some advice:

Use the EDT thread to set the value of the label i.e.

Display.getInstance().callSerially( new Runnable() {
public void run() {
myLabel.setText("123");

}
});

If you want to wait for the repaint, use the callAndWait method.

Also, sometimes its not that the label text is not set, but that the size of the label is too small to show the text. Try using layoutcomponent() on the parent component to reset the layout.

You can also try to set the initial value of the label to something large i.e. setText(" ") to force the initial size to be big enough to hold your values.

I'm sure there are better ways of doing this, but you can try it until you get a better answer.

Claes Insulander

Francis De Brabandere

Are you updating the labels on the edt?

final String result = data.fromserver;
Display.getInstance().callSerially(new Runnable() {
public void run() {
// always update the gui/model on the edt
label.setText(result);
}
});

if the updating thread should block until the label update is done use
callSeriallyAndWait(...

I'm using this helper method in my code:
public static void onEDT(Runnable runnable) {
if (Display.getInstance().isEdt()) {
runnable.run();
} else {
Display.getInstance().callSeriallyAndWait(runnable);
}
}

On Wed, Jul 16, 2008 at 9:03 AM, wrote:
> hi..i got problem now in Label.
>
> i working with some of thread..and many Label.
> i was process incoming data from my web services server, and update it to labels..
>
> some time, when data is incoming, and i update it to my label
>
> -- label.setText(data.fromserver);
>
> it's not update, or the text not change..
>
> example :
> String data from server -> msg= "123";
>
> before update : label's text is set to -> label.setText("-");
>
> after incoming message : label value to be -> label.setText(msg);
>
> so that, in emulator, label value must be "123" ...but in emulator label value still in "-" ...
>
> i really want to know, is the label update or not, show i do print to system.out...
>
> System.out.println("value label = " + label.getText());
>
> the result is -> value label = 123
>
> so, the label in the object was updated but in emulator not display correctly...
> why..?? may be need to be refresh(), repaint() or what..?
> [Message sent by forum member 'sawal_xp' (sawal_xp)]
>
> http://forums.java.net/jive/thread.jspa?messageID=286936
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@lwuit.dev.java.net
> For additional commands, e-mail: users-help@lwuit.dev.java.net
>
>

--
http://www.somatik.be
Microsoft gives you windows, Linux gives you the whole house.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@lwuit.dev.java.net
For additional commands, e-mail: users-help@lwuit.dev.java.net