This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund 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
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Reply 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: 852
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: 8436

John Golt wrote:

Please check your private messages for an important administrative matter


[Donate a pint, save a life!] [How to ask questions] [Onff-turn it on!]
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Custom Multiple Selection for JTree
 
Similar Threads
JTree DnD multiple node selections?
JTree
multiple node selection in jtree
Code for JTree with checkbox
nodes with no children are displayed as a leaf nodes in JTree