aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Multi-use table seletion 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 "Multi-use table seletion" Watch "Multi-use table seletion" New topic
Author

Multi-use table seletion

Dennis Putnam
Ranch Hand

Joined: Feb 03, 2012
Posts: 217
I am not sure if my thinking is correct so am asking for advise. I currently have a JTable set up to allow multiple selection intervals. Then I have menu items that take action based on those selections. All that is working. Under a certain circumstance I disable the menu items that manage selections and instead switch to single selection. I then want to take immediate action when a row is clicked. It is not clear to me how to handle that without interfering with other functionality. If I have things straight in my mind, a default listener is handling the selection logic. However, to do what I want I need to define a new listener to handle the immediate actions. How can I add my special listener then revert to the default listener? Should I write my own listener and just handle both circumstances? If so what do I need in my listener to emulate the default? TIA.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18656
    
    8

So row selection is supposed to work differently in different contexts? And those contexts are identified by selecting some menu items?

Then yes, you have two options: you could have two different listeners, which you assign the appropriate one to the table whenever the context changes. Or alternatively you could have a single listener which, when given a selection event, does one of the two different actions. From the design point of view if the two different modes of operation are very different, then writing two separate listeners would be the way to go. On the hand if they are quite similar, then a single listener which interrogates the context would be the way to go.

If you were asking about programming details, you already know about the addSelectionListener() method (or whatever it's called), and there's also a corresponding removeSelectionListener() method to which you have to pass the same Listener object.
Dennis Putnam
Ranch Hand

Joined: Feb 03, 2012
Posts: 217
Thanks for the reply. I was not aware of removeListSelectionListener(). I think that is the way to go since the default is fine in one context. If I can simply add and remove the listener when the context changes, that will do it.
Dennis Putnam
Ranch Hand

Joined: Feb 03, 2012
Posts: 217
I can't seem to find removeListSelectionListener. Is that a JTable method or something else? Since add is a JTable method, why would remove not be the same class?
Dennis Putnam
Ranch Hand

Joined: Feb 03, 2012
Posts: 217
Never mind. I found it.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Multi-use table seletion