aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Synchorinzing text in JTextField and JList Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Synchorinzing text in JTextField and JList" Watch "Synchorinzing text in JTextField and JList" New topic
Author

Synchorinzing text in JTextField and JList

Andreas Bystrom
Ranch Hand

Joined: Mar 05, 2003
Posts: 32
Hi!
My problem is that I have an GUI that has a list with enteties where each entety has a timer (in seconds) to it. A example of the JList would be this:
Andreas 00:34
Thomas 11:03
Bill 05:43
Each entity has its own clock and the update in bewteen doen't have to be syncronized.
Depending on what item in the list is selected, a second clock is shown in my GUI. This clock should be the same as the one in the JList.
My problem is that if I have a thread that sleeps for 1 sec, and then triggers an update on both the JList and the JtextField to repaint themselvs (whit the new time), they are not update exactly the same time. It is not nice when two clocks that are supposed to show the same time is updated with 0-0,5 seconds differance (sometime the difference is almost nothing and sometime it is up to 0,5 seconds).
How could I solve this? I have tried to use a Document for the clock that is the JTextField, my question is if there is some way to let the JList also be connected to a document in some way. As it is today, I have just overriden the in an extension to JLabel in an implementation of the I use to draw the string for the item (the name and the clock).
I would appreciate if someone can give me some help in this question or give me another apporach to solve this problem
Thanks in advance!
// Andreas
Brian Pipa
Ranch Hand

Joined: Sep 29, 2003
Posts: 299
Here's what I would try if I were doing it (hopefully this isn't a homework question):
What I think I would do is create my own class and call it Clock. That class would display a clock (extend JLabel or JTextArea or whatever) and it would take care of updating itself (i.e. - it would have its own thread or Timer that updates the time). That takes care of all the clocks updating themselves.
Now, for the second display in the GUI of the selected clock, you could make sure the Clock class has a method called getDisplayedTime() then have your GUI clock call that method once per second on the Clock in the selected row.
I think that would work. Maybe.
Brian


My Java Freeware:<br />MACCC - <a href="http://maccc.pipasoft.com" target="_blank" rel="nofollow">http://maccc.pipasoft.com</a><br />Nator - <a href="http://nator.pipasoft.com" target="_blank" rel="nofollow">http://nator.pipasoft.com</a>
Andreas Bystrom
Ranch Hand

Joined: Mar 05, 2003
Posts: 32
I have no problem creating the clock that updates each second. I have a clock class that updates a Document, which is linked to both JTextFields. The problem with this is that I cant get a nice display off the JTextField in a JList. The list should look like this:
icon <tab> name <tab> clock
// Andreas
Brian Pipa
Ranch Hand

Joined: Sep 29, 2003
Posts: 299
If i understand you correctly (and I may not,) maybe you should use a JTable instead? or maybe use 3 different JLists side-by-side?
Brian
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Synchorinzing text in JTextField and JList