This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
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 OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP 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: 19723
    
  20

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: 19723
    
  20

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: label text auto update