• 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
  • Ron McLeod
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Rob Spoor
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Carey Brown
Bartenders:

Switch Selection between 2 JTable?

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

assume that i have 2 JTables in JPanel and each contain one row is it possible to switch selection between these tables

in other words if i select the first table then after that i select the second table the first table will be unselected

this is my attempt but not like what i need

i need to switch selection between the two different tables here in the code when i select one table then select the other table the first table remains selected



any help please !!!
 
Sheriff
Posts: 22716
129
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Add ListSelectionListeners to the JTables through the object returned by getSelectionModel(). When a row is selected in one table you are then notified, and you can clear the selection in the second, and vice versa.
 
Ahmed Aziz
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Rop Prime

i try with this code but still not what i need
 
Ahmed Aziz
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
any help please?
 
Rob Spoor
Sheriff
Posts: 22716
129
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've done a bit of investigation, and the problem is that clearing the selection also triggers an event. So when you select something in the second table the following events are triggered:
1) selection of data in table 2, with getValueIsAdjusting() returning true
2) de-selection of data in table 1, with getValueIsAdjusting() returning false; this event is caused by the previous one
3) de-selection of data in table 2, with getValueIsAdjusting() returning true; this event is caused by the previous one
4) selection of data in table 2, with getValueIsAdjusting() returning false; this event matches the first event

The problem here is that event 2 triggers another event, clearing the selection of table 2. You will need to block this event somehow. I usually use a simple boolean for this. In a short hack based on your code (stripped from the renderers):
 
Ahmed Aziz
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you very much Rob

you solved my problem

Thanks

best wishes
 
reply
    Bookmark Topic Watch Topic
  • New Topic