• Post Reply Bookmark Topic Watch Topic
  • New Topic

Changing Table contents - Urgent

 
Narayanan Jayaraman
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have two JTables extend DefaultTableModel. I would to know how to change the contents of second table when I double click rows in the first table. Thanks
 
Abhik Sarkar
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Narayanan,
Hope the following example I wrote helps... it is very basic, but I am sure it would give you an idea of how to go achieve your goal...
The main class...

TableModel of the dependant table.

Table of the "selector" table.
 
Narayanan Jayaraman
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thats was really helpful to me. Since I am implementing TableModel with DefaultTableModel interface and I have object[][] array, what is the best way of manipulating table contents. I have tried by creating a method in one of my tableModel class but it always gives ArrayOutOfBound Exception. Do I have to recreate JTable and TableModel objects every time user selects a record from first table ? Appreciate your help. Thanks
 
Abhik Sarkar
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am afraid I can't help with the DefaultTableModel. I have always found that creating a TableModel from an AbstractTableModel gives me all the flexibility I need.
Regarding recreating of JTable and TableModel... again, once I have created a TableModel using the AbstractTableModel, I have never had to recreate the Table or the Model when the data inside changes. As you can see in the example I gave, the Table and the Model are created just once.
Best regards,
Abhik.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!