• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

Inserting Record Into JTable For An Specified Interval

 
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

How to insert a new row into JTable at every interval of 5 minutes?
Also how to fix the maximum number of rows in the table? Let it be 50 as maximum number of rows are allowed. At the time of 51st row insertion, it should look for the row which was inserted earliest.

Scenario :

There is a table, "mytable" in database, with columns {createdTime, name, address}.
Now i want to display these data on swing UI based on JTable, which gets refreshed at interval of 5 minutes, i.e if there is insertion of any new in "mytable" during the 5 minute interval, then it should insert the same data into JTable.

Thanks.
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

How to insert a new row into JTable at every interval of 5 minutes?


Check out javax.swing.Timer For more complicated scheduling scenarios google for "Quartz"

Also how to fix the maximum number of rows in the table? Let it be 50 as maximum number of rows are allowed. At the time of 51st row insertion, it should look for the row which was inserted earliest.


Since your data is coming from the DB, the easiest approach would be modify your DB query such that it picks out the latest 50 records based on insertion time or whatever your criteria is.
 
Tanzy Akhtar
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Maneesh,

I tried to implement the JTable. Created my own model by extending "AbstractDataModel" and defined essential method like getValueAt etc. Some methods i want to show :



and to populate data i used this :


And in main method calling in this way :


Now just only one data is being shown in JTable. Where am i doing mistake? Please point it out.
 
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

tanzy akhtar wrote:Hi Maneesh,

I tried to implement the JTable. Created my own model by extending "AbstractDataModel" and defined essential method like getValueAt etc.



I've not heard of "AbstractDataModel" but perhaps you're referring to "AbstractTableModel". If the latter, please note that many of us have had good success using classes that extend DefaultTableModel where much of the model's functionality had already been built for you.

 
Tanzy Akhtar
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I've not heard of "AbstractDataModel" but perhaps you're referring to "AbstractTableModel".


Thank you for coreting me Pete.

Well, some people say that it would be better, if model class extends AbstractTableModel instead of DefaultTableModel.
Let me tell you my need. I need to fire a query, every ten minutes, to database for table "T",having column of type Date,Integer and String.
Now need to show this data on UI using JTable up to maximum 10 rows.
Now let me know your advice, whether it will good to follow DefaultTableModel or need to extend AbstractTableModel?

Thanks,
Tanzy.
 
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi tanzy, you do not need to insert the same data in your jtable object. you only need to insert the data into your table model object

as someone mentioned awhile ago, you can use a Timer for that. or, create your own thread and have your jtable object reload its table model contents every 5 minutes
 
Tanzy Akhtar
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Mark, Pete and Maneesh for helping to resolve the problem.
 
If you open the box, you will find Heisenberg strangling Shrodenger's cat. And waving this tiny ad:
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic