File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes Highlight multiple nodes in jtree Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Highlight multiple nodes in jtree" Watch "Highlight multiple nodes in jtree" New topic

Highlight multiple nodes in jtree

Swetha Krish

Joined: Jun 27, 2011
Posts: 6
There is a search box, on entering the text fireDocumentChangeEvent is done to search the jtree and the matched nodes are selected.
Here only one node is selected and also I have a tree listener which downloads data for the selected node.

My need is If I give the string as "flo" then all the nodes that contains char "flo" should be highlighted.

Darryl Burke

Joined: May 03, 2008
Posts: 5093

So which do you have a problem with?
  • Identifying the nodes that contain "flo"?
  • Selecting multiple nodes?

  • luck, db
    There are no new questions, but there may be new answers.
    Rob Spoor

    Joined: Oct 27, 2005
    Posts: 20193

    If selecting multiple nodes is not possible (because you allow only single selection), use a custom TreeCellRenderer to do the highlighting for you.

    SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
    How To Ask Questions How To Answer Questions
    Darryl Burke

    Joined: May 03, 2008
    Posts: 5093

    Selecting multiple nodes (TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION) is the defaule selectionMode.
    I agree. Here's the link:
    subject: Highlight multiple nodes in jtree
    jQuery in Action, 3rd edition