aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes JTable, reloading the table... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JTable, reloading the table..." Watch "JTable, reloading the table..." New topic
Author

JTable, reloading the table...

Chris Stewart
Ranch Hand

Joined: Sep 14, 2002
Posts: 184
I want to reload the table at certain times in my application. I didn't find a reload method, so I tried doing this but it didn't work. Any ideas?

- getAllStudents returns a 2D object array with all of my info.
- columnData is a 1D object array with the column names.
Chris Stewart
Ranch Hand

Joined: Sep 14, 2002
Posts: 184
Update...
I'm not sure how to update the table, so I'm just using the setValueAt methods from the TableModel object. Problem is my event code continues to run in a loop because I'm changing the table inside of my tableChanged event. Does anyone know how I can get this to work like I want to?
Abhik Sarkar
Ranch Hand

Joined: Jun 14, 2003
Posts: 61
Hi Chris,
If your table's data is going to be dynamic, I would stronly suggest that you write your own TableModel... it will give you a lot more control and I can assure you that it will be worth the additional effort.
However, if you must use the array, this might work...
1. Don't put anything in the event handling code.
2. Change the values directly in the array.
Then,

You should see the updated values in the table.
Hope this helps. I will try and give a working example when I have the time.
Regards,
Abhik.
Chris Stewart
Ranch Hand

Joined: Sep 14, 2002
Posts: 184
I'm getting a ClassCastException on this line of code:
Garandi Garandi
Ranch Hand

Joined: Jan 07, 2003
Posts: 192
If you have extended "AbstractTableModel", then cast to sub-class of AbstractTableModel.

This should do it.
Thank you
Garandi
Now in your code do
Chris Stewart
Ranch Hand

Joined: Sep 14, 2002
Posts: 184
I can't extend anything else because I'm already extending JFrame. Would making another class work?
[ June 20, 2003: Message edited by: Chris Stewart ]
Chris Stewart
Ranch Hand

Joined: Sep 14, 2002
Posts: 184
I tried creating a second class called myModel and extending AbstractTableModel, but on this line:
MyModel model = (MyModel) table.getModel();
I'm getting a ClassCastException.
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

Originally posted by Chris Stewart:
I'm getting a ClassCastException on this line of code:

Why are you casting? I don't think you need to.


GenRocket - Experts at Building Test Data
Chris Stewart
Ranch Hand

Joined: Sep 14, 2002
Posts: 184
Ok, I got it working. Here is the myModel class:

Then in my Layout class, I use this to reload it:
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: JTable, reloading the table...