Skip to main content

Updating label values

3 replies [Last post]
Anonymous

Is there anything in particular that must be done to refresh the value of a
label on screen? Again, keep in mind this is all on BlackBerry

The scenario is the following:

1. I have some information to present and create all components that will
compose the form
2. Most, but not all, components are initialized to the values we have
locally. Others are seeded with place holder values.
3. Data not available locally is then requested
4. On reception of the data from the server, the label is set to the new
value

Unfortunately, on screen, the label still holds the place holder value. I
have to roll over the focus around the form to actually get the updated
value in the label.

--
http://www.spectrumdt.com
http://codepimps.org
[att1.html]

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Shai Almog

Hi,
a label should repaint itself when setText is invoked. I don't see
why the blackberry should be any different, if you can supply us with
a test case that works on the simulator we can look into this.
It might help if you invoke set text using Display.callSerially()
although this should not normally happen...

This works for me:
Form labelForm = new Form("Title");
final Label l = new Label("Counter: N/A");
labelForm.addComponent(l);
new Thread() {
public void run() {
for(int iter = 0 ; iter < 1000000 ; iter++) {
try {
l.setText("Counter: " + iter);
Thread.sleep(2);
} catch (InterruptedException ex) {
ex.printStackTrace();
}
}
}
}.start();
labelForm.show();

Although occasionally the size of the area grows triggering a need to
relayout the component which will only happen if you scroll or cause
a parent repaint.

Thanks

> Is there anything in particular that must be done to refresh the
> value of a label on screen? Again, keep in mind this is all on
> BlackBerry
>
> The scenario is the following:
>
> 1. I have some information to present and create all components
> that will compose the form
> 2. Most, but not all, components are initialized to the values we
> have locally. Others are seeded with place holder values.
> 3. Data not available locally is then requested
> 4. On reception of the data from the server, the label is set to
> the new value
>
> Unfortunately, on screen, the label still holds the place holder
> value. I have to roll over the focus around the form to actually
> get the updated value in the label.
>
>
> --
> http://www.spectrumdt.com
> http://codepimps.org

Shai Almog
http://lwuit.blogspot.com/

[att1.html]

Patrick Julien

It was already using call serially. But your mail still had the solution in
it. Putting a larger value initially (data not yet available) then putting
in the value works.

Any way to re-layout the component manually?

On Tue, Jul 22, 2008 at 11:43 PM, Shai Almog wrote:

> Hi,
> a label should repaint itself when setText is invoked. I don't see why the
> blackberry should be any different, if you can supply us with a test case
> that works on the simulator we can look into this.
> It might help if you invoke set text using Display.callSerially() although
> this should not normally happen...
>
> This works for me:
> Form labelForm = new Form("Title");
> final Label l = new Label("Counter: N/A");
> labelForm.addComponent(l);
> new Thread() {
> public void run() {
> for(int iter = 0 ; iter < 1000000 ; iter++) {
> try {
> l.setText("Counter: " + iter);
> Thread.sleep(2);
> } catch (InterruptedException ex) {
> ex.printStackTrace();
> }
> }
> }
> }.start();
> labelForm.show();
>
> Although occasionally the size of the area grows triggering a need to
> relayout the component which will only happen if you scroll or cause a
> parent repaint.
>
> Thanks
>
> Is there anything in particular that must be done to refresh the value of a
> label on screen? Again, keep in mind this is all on BlackBerry
>
> The scenario is the following:
>
> 1. I have some information to present and create all components that will
> compose the form
> 2. Most, but not all, components are initialized to the values we have
> locally. Others are seeded with place holder values.
> 3. Data not available locally is then requested
> 4. On reception of the data from the server, the label is set to the new
> value
>
> Unfortunately, on screen, the label still holds the place holder value. I
> have to roll over the focus around the form to actually get the updated
> value in the label.
>
>
> --
> http://www.spectrumdt.com
> http://codepimps.org
>
>
> Shai Almog
> http://lwuit.blogspot.com/
>
>

--
http://www.spectrumdt.com
http://codepimps.org
[att1.html]

Shai Almog

Sure,
repaint should do it if you already called setText(). The call to set
text marks the component as "dirty" but won't reflow the layout which
is expensive. Calling repaint on the parent will do that for you.
You can force layout by calling revalidate, but I don't recommend
that in general.

Thanks.
> It was already using call serially. But your mail still had the
> solution in it. Putting a larger value initially (data not yet
> available) then putting in the value works.
>
> Any way to re-layout the component manually?

Shai Almog
http://lwuit.blogspot.com/

[att1.html]