Results 1 to 4 of 4
- 08-05-2009, 01:16 PM #1Member
- Join Date
- Aug 2009
- Rep Power
Dynamic Refresh in JTable every 5 Minutes
I have developed JTable and it displays the data in table.
But i want the Jtable to update the content every five minutes
and the newly added Records(data) should be always at first and
old records Should be below (Similar to Stack Opeartions)
Record is read from the txt file.the txt file updated every three minutes.
So kindly Give an idea to solve these problems:) javadeveloper
- 08-05-2009, 02:11 PM #2
Hmm. TimerTask to schedule the reading. Read the file, reverse the lines (I reckon new lines are at the bottom of the file), populate a new TableModel and set that to your table.
Or perhaps a javax.swing.Timer, but whichever you use, you should take care to do the file reading in a background thread and the JTable/table model manipulations on the EDT (sorry if you already know this). A Swing Timer will do everything on the EDT, so I would use it in conjunction with a SwingWorker object. Also, if you extend an AbstractTableModel, the data itself can be held in a stack.
Last edited by Fubarable; 08-05-2009 at 04:28 PM.
- 08-07-2009, 06:16 AM #4
Given the long periods of time between updates and the (potential) need to do the data updates off the EDT, I would just use a thread. Have it do sleep(100) and check for a "stop" flag between updates. Once the update information is collected, post the update using EventQueue.invokeLater(). This is a very simple approach and it is extensible.
As far as your table, implement your own TableModel class. Don't do any of the array of array nonsense. Create a simple Row class, and put the rows in a list. Put the new row on top of the list. Clean and simple.
- By neha_negi in forum Threads and SynchronizationReplies: 3Last Post: 09-04-2009, 02:45 AM
- By paty in forum JDBCReplies: 3Last Post: 08-17-2008, 01:01 PM
- By eftenpuften in forum AWT / SwingReplies: 0Last Post: 07-24-2008, 04:41 PM
- By salmanpirzada1 in forum Advanced JavaReplies: 2Last Post: 05-15-2008, 11:15 AM
- By Java Tip in forum java.langReplies: 0Last Post: 04-16-2008, 11:40 PM