• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Custom Multiple Selection for JTree

 
Vitaly Karnyushin
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 908
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Maneesh Godbole
Saloon Keeper
Posts: 11196
15
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
John Golt wrote:

Please check your private messages for an important administrative matter
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic