This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
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
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
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
Joined: Sep 29, 2003
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