GeeCON Prague 2014*
The moose likes Swing / AWT / SWT and the fly likes multiple node selection in jtree Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "multiple node selection in jtree" Watch "multiple node selection in jtree" New topic
Author

multiple node selection in jtree

pavan in
Ranch Hand

Joined: Oct 22, 2002
Posts: 64
I have a jtree. I have set selection mode as SINGLE_TREE_SELECTION. (f_jtree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION) . But, on initial load of jtree, I am pre-selecting a node. If the nodes of same id are found, then I'll have to select all the nodes matched. Is it possible to select only a single node(ay, select the first node found) and make some asthetic change (like change the background) for other nodes of similar id?
Thanks
Chantal Ackermann
Ranch Hand

Joined: Sep 28, 2000
Posts: 508
you could start the tree with multiple selection and change to single selection as soon as the user selects a node, the first time. I think, this is the easiest solution. I am doing that in a table to mark search events - each time a search produces hits, I select all the matching rows (after changing to multiple selection), and as soon as the user clicks in the table, the selection mode is changed bach to single selection. this works very fine and fast.
if you want to change the background of some nodes you will have to implement a TreeCellRenderer that checks for this special ID and paints the background of the nodes appropriately. as the ID is set dynamically you would have to design the API of the renderer accordingly: implement a setID() method and fire an event (from the controller or the treemodel) that notifies the tree to update itself.
chantal
[ November 22, 2002: Message edited by: Chantal Ackermann ]
 
GeeCON Prague 2014
 
subject: multiple node selection in jtree