• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Selecting a row in one JTable should select the same row in another JTable

 
Ramu Eedupalli
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have two JTables and i am using one TableModel for two JTables. If I select a row in one JTable then how to automatically select the same row in another JTable? I tried it by overriding valueChanged function in one JTable, if selection changed then i am selecting same row of another JTable in valueChanged function. This is working but If the data in TableModel changed then I am getting exceptions.
 
Rob Spoor
Sheriff
Pie
Posts: 20661
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check out what JTable.getSelectionModel() returns, and what methods it has.
 
Maneesh Godbole
Saloon Keeper
Posts: 11173
14
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JTable also offers a set selection model as well.
Sharing the same selection model between the tables should fix your problem.
 
Ramu Eedupalli
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you. It solved the problem.
 
Rob Spoor
Sheriff
Pie
Posts: 20661
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maneesh Godbole wrote:JTable also offers a set selection model as well.
Sharing the same selection model between the tables should fix your problem.

Why do I also miss the easiest solutions?
 
Maneesh Godbole
Saloon Keeper
Posts: 11173
14
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because it was your turn this time
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic