refresh label awt


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: refresh label awt

  1. #1
    RC Guest

    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

  2. #2
    Kent Guest

    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



  3. #3
    Kent Guest

    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
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center