• 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

Dynamic JTable

 
Ranch Hand
Posts: 375
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've tried everything, including a search on the ranch but I couldn't really find a good example to get me started. Simply put, what I need to do is make a JTable dynamically grow by taking selected rows from some other table.
I'd appreciate if you could tell me what goes in the addSelectedmethod in the code below. I'd also like to have a handle to the underlying TableModel for this dynamic table so that I can then print out all the rows that were added to the dynamic table.
Code overview -
There are 2 tables, dataTable & scheduledTable
dataTable provides the data & you can respawn it with the "Respawn" button
Rows with the boolean column selected in dataTable should be added to the scheuledTable when the user clicks "Add"
Respawn, select & add to make the scheduledTable grow dynamically without loosing any previous rows.

Thanx
Ashish Hareet
 
Ranch Hand
Posts: 508
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
add to your table model a method:

the JTable is listening to model updates by default. it will update the view automatically.
(sorry if I missed some point and did not answer the question!)
cheers,
Chantal
 
Ashish Hareet
Ranch Hand
Posts: 375
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Chantal,
Thanx for the response.Your method worked great but then I chose to use the DefaultTableModel.
Here's the changes to the code -

And the addSelected method goes like this

I subclassed the DefaultTableModel for the scheduledTable's TableModel so that I benefit from it's addRow method & I made the cell's not editable - the scheme worked fine.
I had anticipated that the DefaultTableModel object with no args supplied to scheduledTable's constructor(from my first post) should be responsible for updating the table. But right now I realised that the I need to atleast give it the count for the number of columns, that's were I was stuck.
Thanx a lot
Ashish Hareet
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic