This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes refresh a JPanel automatically as time changes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "refresh a JPanel automatically as time changes" Watch "refresh a JPanel automatically as time changes" New topic
Author

refresh a JPanel automatically as time changes

partha phukan
Ranch Hand

Joined: Mar 13, 2011
Posts: 31
Sir/ Madam, i am facing a problem and i do not have any idea how to do. i face a problem regarding how to refresh a JPanel in a timely manner. I have three JLabel in a JPanel which get value from database. now my database is maintaining a table where i have values in a timely manner within an interval of 1 hour. now i have to refresh my JLabel values i.e refresh JPanel so that as time changes i can display the new data from the database.

For example- when time is 09:00:00 then i must display the data of 09:00:00 in JLabels, but as soon time changes to 10:00:00 then i need to display the 10:00:00 datas in JLabels. In between 09:00:00 to 09:59:59 the data must remain same i.e JLabels should display the 09:00:00 data. Only when it changes to 10:00:00 then only the JLabel should be modified with 10:00:00 data and it must remain same till 10:59:59.

Please, help me in this regard. Any help from you will highly be appreciated. Thank you in advance.

Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3068
    
  33

You can use a Timer and then keep calling revalidate() method.

And welcome to JavaRanch


Mohamed Sanaulla | My Blog
partha phukan
Ranch Hand

Joined: Mar 13, 2011
Posts: 31
Thank you Sir for your suggestion, but i do not have any idea that what must be the time delay i should give. can i use repaint() method? again i want to ask you something whether i have to declare my query to retrieve data in the action performed method?

please sir, help me here. i know little about timers and schedule. please give me some suggestion or some link so that i can proceed further...
Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3068
    
  33

I havent used Timer myself. The delay would depend on how often you want the action to be performed. You can call the revalidate() method on JLabel object. Querying for data on a frequent basis might have performance impact. But again it depends on the requirements- If you have to fetch the fresh data after some interval then you would have to call the method which fetches the data with in the Action listener for the Timer.
partha phukan
Ranch Hand

Joined: Mar 13, 2011
Posts: 31
Thank you sir, your suggestion has given me a clue and given me the idea to think and do something and try.....

Thank you once again for giving me your valuable time.........
Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3068
    
  33

Posted similar question but in a different way: http://www.java-forums.org/awt-swing/40442-how-refresh-contents-jpanel.html
partha phukan
Ranch Hand

Joined: Mar 13, 2011
Posts: 31
Sir, still i cannot able to find the right track that where to use timers and what will be the delay to be set. i have two seperate classes-

1. One class that reads the data from the database and display in the JLabels.
2.Another separate class with queries and methods that return the data from the DB.

Now where to use timers? I am confused. please give me some suggestion.

Thank u.
partha phukan
Ranch Hand

Joined: Mar 13, 2011
Posts: 31
hello everyone, i am using a JPanel and there i have displayed two graphs. Now my problem is that i could not able to display them properly. I am using BorderLayout, but still i can not able to display them properly. can anyone help me and give me some suggestion that which layout i should use to display the graphs.

thank you in advance.
Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3068
    
  33

partha phukan wrote:hello everyone, i am using a JPanel and there i have displayed two graphs. Now my problem is that i could not able to display them properly. I am using BorderLayout, but still i can not able to display them properly. can anyone help me and give me some suggestion that which layout i should use to display the graphs.

thank you in advance.

Please UseOneThreadPerQuestion
 
Don't get me started about those stupid light bulbs.
 
subject: refresh a JPanel automatically as time changes
 
Similar Threads
problem in refreshing JPanels
refresh a JPanel automatically with time
urgent please
JLabels not displaying
need sugesition