Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Use same object on different components  RSS feed

 
Jennifer Sohl
Ranch Hand
Posts: 455
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have an instance of a label that displays the current system time. I want to pass this to 3 different components to display on all of them. However, it only shows the clock on the last component it is added to. I don't want to create 3 different instances of this clock, because then I would have to create 3 separate threads for the time, resulting in the clocks not being identical.

Can anyone tell me how to display the same object on three different components?

Thanks!
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A component can only have 1 parent. So the only thing you would be able to do is abstract the actual clock (non GUI) away from the JLabel. Create as many JLabel instances as you want and update each of them with the clock value, which you can make static so that there is only one in memory.

Think MVC. The JLabel is the view. The clock is the model.
[ October 08, 2004: Message edited by: Gregg Bolinger ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!