-
refresh label awt
How can I 'refresh' the display of an awt label to show that a value has changed.
I monitor a socket an when a value changes I want the screen to update.
thanks
-
Re: refresh label awt
RC,
The simple answer is to invoke setText() on the label. This causes repaint()
to be called on the label.
By the sound of things, though, you are monitoring the socket in a separate
thread (ie. not the GUI thread)?
If so, you will need to use the static method invokeAndWait or invokeLater
in the SwingUtilities class. These are provided to allow non-GUI threads
to modify the GUI because it is not thread-safe to do so directly.
Here is how you can use this method:
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
//change the label text here calling setText()
}
});
Regards,
Kent
"RC" <java.@127.0.0.1> wrote:
>
>How can I 'refresh' the display of an awt label to show that a value has
changed.
>I monitor a socket an when a value changes I want the screen to update.
>
>thanks
-
Re: refresh label awt
Whoops, just read your title and realised you're using AWT. Everything I said
still applies except that calling setText() on the label does not automatically
update the display (not from the source code I just looked at anyway).
So call setText() and then repaint(). That should do it.
Regards,
Kent
"Kent" <kb@essential.com.au> wrote:
>
>RC,
>
>The simple answer is to invoke setText() on the label. This causes repaint()
>to be called on the label.
>
>By the sound of things, though, you are monitoring the socket in a separate
>thread (ie. not the GUI thread)?
>
>If so, you will need to use the static method invokeAndWait or invokeLater
>in the SwingUtilities class. These are provided to allow non-GUI threads
>to modify the GUI because it is not thread-safe to do so directly.
>
>Here is how you can use this method:
>
>SwingUtilities.invokeAndWait(new Runnable() {
> public void run() {
> //change the label text here calling setText()
> }
>});
>
>Regards,
>Kent
>
>
>"RC" <java.@127.0.0.1> wrote:
>>
>>How can I 'refresh' the display of an awt label to show that a value has
>changed.
>>I monitor a socket an when a value changes I want the screen to update.
>>
>>thanks
>
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks