• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JTable, reloading the table...

 
Ranch Hand
Posts: 184
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 184
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 184
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm getting a ClassCastException on this line of code:
 
Ranch Hand
Posts: 192
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 184
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 184
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Chris Stewart
Ranch Hand
Posts: 184
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, I got it working. Here is the myModel class:

Then in my Layout class, I use this to reload it:
 
reply
    Bookmark Topic Watch Topic
  • New Topic