This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes Custom Multiple Selection for JTree Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Custom Multiple Selection for JTree" Watch "Custom Multiple Selection for JTree" New topic
Author

Custom Multiple Selection for JTree

Vitaly Karnyushin
Greenhorn

Joined: Apr 23, 2010
Posts: 1
Hi,

I need to implement specific multiple selection behavior.
The multiple selection should be worked for the nodes of one level.
As an illustration, if I have two expanded nodes with some amount of children in my view and one of the parents is already selected then multiple selection action should select only second one parent, children should be ignored.

Any advices how to properly implement that?

Thanks,
Vitaly
Brian Cole
Author
Ranch Hand

Joined: Sep 20, 2005
Posts: 862
John Golt wrote:I need to implement specific multiple selection behavior.
The multiple selection should be worked for the nodes of one level.
As an illustration, if I have two expanded nodes with some amount of children in my view and one of the parents is already selected then multiple selection action should select only second one parent, children should be ignored.

Any advices how to properly implement that?


I'm not I understand exactly what you want (Do you really want selection to behave differently depending on whether a node is currently visible in the view??) but have you looked at the TreeSelectionModel interface? You can write your own and do anything you want in the addSelectionPath() addSelectionPaths() methods, including ignoring certain paths, or substituting others, or deselecting others. You just have to make sure you fire the correct events.

It may be easier to extend DefaultTreeSelectionModel, since it provides and implementation for most of the event stuff.

bitguru blog
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10172
    
    8

John Golt wrote:

Please check your private messages for an important administrative matter


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
 
 
subject: Custom Multiple Selection for JTree
 
Similar Threads
multiple node selection in jtree
Code for JTree with checkbox
nodes with no children are displayed as a leaf nodes in JTree
JTree
JTree DnD multiple node selections?