| 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: 19216
|
|
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
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: 19216
|
|
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
|
 |
 |
|
|
subject: label text auto update
|
|
|