• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to detect row deselect in JTable

 
Avi Abrami
Ranch Hand
Posts: 1141
1
Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JDK 1.6.0_21 on Windows 2000
I want to know which row of a JTable was removed from the set of selected rows.
 
Rob Camick
Ranch Hand
Posts: 2613
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Avi Abrami
Ranch Hand
Posts: 1141
1
Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Rob.
Now please pardon my ignorance, but how would I implement my ListSelectionListener interface in order to detect rows that were deselected.
 
Darryl Burke
Bartender
Posts: 5148
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cache the selected indices in a int[] or List<Integer> and iterate over the list comparing with the new selection to find the changes

Alternatively, extend DefaultListSelectionModel and override methods that can deselect an item.
 
Avi Abrami
Ranch Hand
Posts: 1141
1
Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Darryl.
Your caching suggestion was how I thought to do it also but I thought perhaps there is some ready-made solution hiding in the Swing API somewhere that I was not aware of.
Cheers!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic