Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

multiple node selection in jtree

 
pavan in
Ranch Hand
Posts: 64
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 508
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic