wood burning stoves*
The moose likes Swing / AWT / SWT and the fly likes JTable refreshment -- or was that 7up? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JTable refreshment -- or was that 7up?" Watch "JTable refreshment -- or was that 7up?" New topic
Author

JTable refreshment -- or was that 7up?

Greg Reeder
Ranch Hand

Joined: Jun 14, 2011
Posts: 99

My goal is this:
to have a single window that shows me information from an SQLite3 database for 1 month. Then to have the option with a click of a button to go forward in time, or backward in time, and show the new information.

What I have:
I have the code to get the correct information out of the database. I have an entire class dedicated to the table model and data, and creating the table. I have a JFrame with buttons for the time controls, and a JScrollPane which is houses the JTable with the information.

My issue:
When I click on one of the buttons which gets a new table with information from a differant month, I cannot get that new table to show in the window. I know that the constuctors are being called, it is like I cannot destroy the exsisting table and add the new one.

Does anyone have any ideas what I am doing wrong?

Thank you,

Greg
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4523
    
    5

Don't change the table, just set the existing table's model.


luck, db
There are no new questions, but there may be new answers.
Arun Chidam
Ranch Hand

Joined: May 08, 2006
Posts: 79
Hi Greg,

hope you are not missing the below bit of code on update...



Thanks,
Arun


SCJP 1.4, SCWCD 1.4
Greg Reeder
Ranch Hand

Joined: Jun 14, 2011
Posts: 99

doesnt .tableChanged refer to the user editing a cell in the table? Right now, my table is not editable and this change of month is being performed via button actions.
Arun Chidam
Ranch Hand

Joined: May 08, 2006
Posts: 79
Greg Reeder wrote:doesnt .tableChanged refer to the user editing a cell in the table? Right now, my table is not editable and this change of month is being performed via button actions.


Hi Greg,

If you are using custom data model (i.e by extending AbstractTableModel), you can either use either setValue method by overriding the super class implementation and call firetable changed event(for this you need to set editable as true), else you can use setModal by updating the records in the dataModal and set the modal in your table and call repaint Method.

If you look into the setModal method source code you will notice, it inturn calls the tablechanged event when a modal is set....my code is in same logic as in setModel, where i update the model in a vector and then forward the notification event to all registered listners from this model and repaint the table.

Seniors please correct me if iam wrong

Rob Camick
Ranch Hand

Joined: Jun 13, 2009
Posts: 2156
    
    7
As Darryl suggest you don't need to create a new table. Just use:



There is no need to invoke the tableChanged() or repaint() method. The setModel() method will notify the table that the data has changed and the table will repaint itself automatically.
Greg Reeder
Ranch Hand

Joined: Jun 14, 2011
Posts: 99

Thank you very much. I finally got the thing working. I had to rework the way I had the table set up. I wanted to have the table in a seperate class with the inherited table model as a sub class (inner class), but that led to me not being able to update the table. I wanted to be able to put this table into any other jdialog or jframe I wanted. I am sure that there was a way to be able to make that work, but I dont want to be fighting for days over the same table. I put the whole table and inherited table model code into the Jframe code and used table.setModel, and now it all works wonderfully. Thank you all for the help.

Greg
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JTable refreshment -- or was that 7up?
 
Similar Threads
JTable problem
JTable
jtable
JTable
Columns on JTable