File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes Refreshing a GUI Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Refreshing a GUI" Watch "Refreshing a GUI" New topic

Refreshing a GUI

Fred Victa
Ranch Hand

Joined: May 01, 2008
Posts: 173
I have an application that displays a GUI and this GUI displays a table with several columns and rows. I have a class that extends DefaultTableModel. I wrote the code that displays the GUI. When the database table changes, how would I updated the GUI dynamically? Do you have any sample code that does that?
Steve Luke

Joined: Jan 28, 2003
Posts: 4181

Does your database have a feature that would allow it to call arbitrary Java Code when it is updated? Is the update happening from your Java code or do you have to respond to changes that occur to the table from outside your application? You have to determine these things in order to work out a strategy which lets you determine when the data has changed. You might have to have some thread periodically polling the data table for differences (using timestamps when you submit rows helps with this), or, if you are in control of when the data gets sent into the DB then maybe you could register a callback which gets informed when you commit the changes.

Fred Victa
Ranch Hand

Joined: May 01, 2008
Posts: 173
My Java code adds new records to the database table and it also updates the records. I would like to refresh the GUI after my Java code adds or updates records in the table, but I'm not sure how to do that.
Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2446
The DefaultTableModel has methods like:

So you can use those methods to update the TableModel at the same time you update your database.

I agree. Here's the link:
subject: Refreshing a GUI
It's not a secret anymore!