This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
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
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Reply 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: 19216

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


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

Joined: Jul 26, 2007
Posts: 8434

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


[Donate a pint, save a life!] [How to ask questions] [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: 19216

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: 8434

Because it was your turn this time
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Selecting a row in one JTable should select the same row in another JTable
 
Similar Threads
Using a the selected JTable name
JTable
JTable blues
refreshing a JTable
Jtable