• Post Reply Bookmark Topic Watch Topic
  • New Topic

Update Table Rows All The Time

 
David Weber
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

Here's my situation,

I have a JFrame with a tabbed pane. Inside the tabbed pane is a table containing orders.

These orders are received as an ArrayList from a rmi method which gets the orders from the database.

Now I want the table to constantly be updated, as orders are being added/edited all the time.

At the moment i'm simply implementing Runnable on my JFrame like this:



Now seems to work fine, but i do get this exception if i'm currently selecting the table and it updates.



Any of you Java 'gods' got any advice for me??

Much appreciated guys,

Regards,

David
 
Paul Clapham
Sheriff
Posts: 21889
36
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As for the first question, you might find that removing the "sleep" from the loop makes your program, or your database, or some other component, work too hard. But you might also find that every 10 seconds is too infrequent; that would depend on the volatility of the orders and also the requirement to see new orders "instantly".

As for the second question, go through the Concurrency in Swing tutorial.
 
Vivek Singh
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't rely on threads...
Better option would be make a job. Run thar job using a schedular. say for a time of 4 seconds or according to your need.

Add a finally block add schedular there.


sleep() is not a good option.
 
David Weber
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your input guys,

read up on concurrency and have now implemented ActionListener,
using swing.timer to execute the table update every 3 seconds
this is using the event-dispatch thread and so is safe to use for gui updating.

I think my problem is Solved
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!