I have created a java class with two JtabbedPane and i need to refresh these two panels every 10 seconds... I tried repaint(), revalidate(), validate functions.... But no fruitful has emerged so far... Could you some one please help me on this...
Thanks in advance... I am placing my sample code here for your reference... Your help would be really appreciated...Thanks
In Swing and AWT, there is the Event Dispatcher Thread (EDT). This is one single thread that does many things, including handling user input (typing, mouse clicks, etc) and repainting the user interface. This means you shouldn't do anything lengthy in the EDT, and that includes code inside listeners. Otherwise, when you click a button, the entire user interface hangs until that handling method ends.
Another important issue is that changes to the user interface should be done from the EDT as well, or you may get errors. I've seen lots of ArrayIndexOutOfBoundsExceptions because changes were done from another thread.
You said you want to repaint every 10 seconds. That means you need to use some kind of timer. That Thread.sleep(1000 * 10) is wrong for two reasons:
1) it is one single sleep of 10.000 milliseconds (10 seconds).
2) if you do this in the EDT your user interface will do nothing else for the full 10 seconds.
Both could do what you want but the second has one advantage: it runs on the EDT. That means you don't have to perform "tricks" like using EventQueue.invokeLater. You can simply put your code in the ActionListener's actionPerformed method and be done.
So, for example:
Joined: Nov 30, 2010
Thank you so much for your quick response. After i placed my code action performed method it was repeating for every 10 seconds. But the JTabbedane is not refreshed and i seeing the my old data only. Here is my latest code for your reference.