aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Selecting a row in one JTable should select the same row in another JTable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Selecting a row in one JTable should select the same row in another JTable" Watch "Selecting a row in one JTable should select the same row in another JTable" New topic
Author

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

Ramu Eedupalli
Greenhorn

Joined: Apr 10, 2009
Posts: 9
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

Joined: Oct 27, 2005
Posts: 19720
    
  20

Check out what JTable.getSelectionModel() returns, and what methods it has.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10451
    
    8

JTable also offers a set selection model as well.
Sharing the same selection model between the tables should fix your problem.


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Ramu Eedupalli
Greenhorn

Joined: Apr 10, 2009
Posts: 9
Thank you. It solved the problem.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19720
    
  20

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

Joined: Jul 26, 2007
Posts: 10451
    
    8

Because it was your turn this time
 
Don't get me started about those stupid light bulbs.
 
subject: Selecting a row in one JTable should select the same row in another JTable