• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JTable refreshment -- or was that 7up?

 
Greg Reeder
Ranch Hand
Posts: 99
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5148
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't change the table, just set the existing table's model.
 
Arun Chidam
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Greg,

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



Thanks,
Arun
 
Greg Reeder
Ranch Hand
Posts: 99
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2619
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 99
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic