• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Paweł Baczyński
  • Piet Souris
  • Vijitha Kumara

refresh a JPanel automatically as time changes

 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
Bartender
Posts: 3225
34
IntelliJ IDE Oracle Spring Chrome Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use a Timer and then keep calling revalidate() method.

And welcome to JavaRanch
 
partha phukan
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Bartender
Posts: 3225
34
IntelliJ IDE Oracle Spring Chrome Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Bartender
Posts: 3225
34
IntelliJ IDE Oracle Spring Chrome Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Bartender
Posts: 3225
34
IntelliJ IDE Oracle Spring Chrome Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
 
This looks like a job for .... legal tender! It says so right in this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!