wood burning stoves 2.0*
The moose likes Swing / AWT / SWT and the fly likes label text auto update Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "label text auto update" Watch "label text auto update" New topic
Author

label text auto update

Ayy Looz
Greenhorn

Joined: Mar 04, 2009
Posts: 4
how can i make labels "listen" to changes (in a String[] array for example) ??

i mean, i have an array that is updated whenever a change occurs to a server (that i monitor)

i want the labels to be "in sync" with the array content

can i do that ?
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19649
    
  18

You could wrap the array in a wrapper class, and make that class fire events.

For instance:

Usage:

You just have to make sure that all access to the array is done through the wrapper class.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Ayy Looz
Greenhorn

Joined: Mar 04, 2009
Posts: 4
sorry but i'm a java newbie, i couldnt figure out how to use that code to auto update the label's text :/
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19649
    
  18

You need to keep an association between the JLabels and the array indexes. Storing the JLabels in their own array would be easiest. After retrieving the index as I have already shown, you simply retrieve the JLabel and change its text:
Ayy Looz
Greenhorn

Joined: Mar 04, 2009
Posts: 4
thank you very much
i'll give it a try
 
Don't get me started about those stupid light bulbs.
 
subject: label text auto update
 
Similar Threads
multidimensional arraylist of JTextFields
Order of adding components
AWT
Order of adding components
Order of adding components