changing an icon on node in jtree

Posted on 2005-05-11
Last Modified: 2010-03-31
I have an applet with one tree and 2 buttons "open" and "close". When I click open button, I want to change the image icon of the node which were selected on the tree.
Please give me the idea.
Question by:nphnhi
    LVL 37

    Accepted Solution

    LVL 92

    Expert Comment

    exactly which icon is it you want to change?
    you could try a defaultmutabletreenode with an ImageIcon as the nodes user object

    LVL 92

    Expert Comment


    Author Comment

    for example, each node is a project with an icon "project_normal.gif". When I click open button, I want to change to "project_open.gif"
    LVL 92

    Assisted Solution

    the following may be enough (add this before you create your tree):

    UIManager.put ( "Tree.leafIcon", normalIcon ) ;
    UIManager.put ( "Tree.openIcon", openIcon ) ;
    UIManager.put ( "Tree.closedIcon", normalIcon ) ;

    Otherwise see the example I posted above

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
    Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
    Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
    This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    7 Experts available now in Live!

    Get 1:1 Help Now