Results 1 to 4 of 4
  1. #1
    Join Date
    Aug 2009
    Posts
    21
    Rep Power
    0

    Smile 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

  2. #2
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,430
    Rep Power
    7

    Default

    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.

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    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 03:28 PM.

  4. #4
    Steve11235's Avatar
    Steve11235 is offline Senior Member
    Join Date
    Dec 2008
    Posts
    1,046
    Rep Power
    7

    Default

    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.

Similar Threads

  1. Inside a Timer thread loop,how to refresh a JTable in swing
    By neha_negi in forum Threads and Synchronization
    Replies: 3
    Last Post: 09-04-2009, 01:45 AM
  2. how to refresh data of the JTable
    By paty in forum JDBC
    Replies: 3
    Last Post: 08-17-2008, 12:01 PM
  3. Dynamic JTable
    By eftenpuften in forum AWT / Swing
    Replies: 0
    Last Post: 07-24-2008, 03:41 PM
  4. Replies: 2
    Last Post: 05-15-2008, 10:15 AM
  5. How to beep every 5 minutes in Java
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-16-2008, 10:40 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •