This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Swing / AWT / SWT and the fly likes JTree Selection Customization Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JTree Selection Customization" Watch "JTree Selection Customization" New topic
Author

JTree Selection Customization

Johann Dobbins
Ranch Hand

Joined: Oct 16, 2008
Posts: 62
I have implemented a DragAndDrop tree and want to control when treeSelection events get fired.

My tree allows selection of multiple nodes, you can ctrl+click on multiple nodes and they will all appear as selected. Single clicking on any of the selected nodes will change the selection to be just that node. I would like to change this so that a mouse pressed event on a selected node does not change the selction, but a mouse clicked or mouse released event does. This way, a user could press on a selection and drag the entire group elsewhere.

I assume to do this I need to extend whatever class owns the mouse listener that fires treeSelection events and customize the logic for when these events get fired. But I can't find this class.

Thank You
Mark Vedder
Ranch Hand

Joined: Dec 17, 2003
Posts: 624

I haven't used TreeSelectionEvents much, so I cannot answer your question directly. But something that may help you is the following... and it may help you solve other problems in the future... If you go to the TreeSelectionEvent class, or any class or interface, in the JavaDoc API, at the top is a series of links with a light blue background: "Overview, Package, Class, Use, Tree, Deprecated, Index, Help". Click on the "Use" link. It will show you a list of all other (known) classes and methods that use that class. It will give you a list of methods that use that class as an argument, methods that return that class, public fields that have that class as a type, etc. In the case of the TreeSelectionEvent, there is a rather limited number methods that use it. From that you can probably find what you are looking for.

I hope that helps.
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10268
    
    8

Johann Dobbins wrote:I would like to change this so that a mouse pressed event on a selected node does not change the selction, but a mouse clicked or mouse released event does. This way, a user could press on a selection and drag the entire group elsewhere.


will do the trick


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JTree Selection Customization