my dog learned polymorphism*
The moose likes Swing / AWT / SWT and the fly likes How to detect row deselect in JTable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "How to detect row deselect in JTable" Watch "How to detect row deselect in JTable" New topic
Author

How to detect row deselect in JTable

Avi Abrami
Ranch Hand

Joined: Oct 11, 2000
Posts: 1135

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

Joined: Jun 13, 2009
Posts: 2227
    
    8
Avi Abrami
Ranch Hand

Joined: Oct 11, 2000
Posts: 1135

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

Joined: May 03, 2008
Posts: 4664
    
    5

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.


luck, db
There are no new questions, but there may be new answers.
Avi Abrami
Ranch Hand

Joined: Oct 11, 2000
Posts: 1135

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!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to detect row deselect in JTable