• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

label text auto update

 
Ayy Looz
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20369
44
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ayy Looz
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20369
44
Chrome Eclipse IDE Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you very much
i'll give it a try
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic