JTree Expanded Icon

How can I change the icon in the JTree of JavaHelps TOC when I expand or close the node. I understand that I need to give the tree a different cell renderer but can't find out where to do that. Does anyone have an example of this?
Thanks,
Rich
Developer

Thankyou for your help. I am getting a lot closer. There is something I am still missing though. I am sure I am setting the cell renderer to the tree now. The problem is that it is not effecting the images at all. Here is my code for this. Can you see what I am doing wrong?
private void jButtonHelp_ActionPerformed()
          try
               ClassLoader loader = this.getClass().getClassLoader();
               URL helpURL = HelpSet.findHelpSet(loader, "helpset.hs");
               m_hs = new HelpSet(loader, helpURL);
               HelpBroker hb = m_hs.createHelpBroker();
               JHelp jhelp = new JHelp(m_hs);
               JHelpTOCNavigator jhtoc = null;
               hb.setDisplayed(true);
               new CSH.DisplayHelpFromSource(hb);
               for(Enumeration enum = jhelp.getHelpNavigators();enum.hasMoreElements();)
                    try
                         jhtoc = (JHelpTOCNavigator)enum.nextElement();
                         break;
                    catch(Exception ee){}
               if(jhtoc != null)
                    JTree aTree = getNavTree(jhtoc);
                    aTree.setCellRenderer(new HelpTreeRenderer());
                    aTree.updateUI();
                    jhelp.updateUI();
          catch (Exception e)
               System.out.println("Help Exception " + e.getMessage());
class HelpTreeRenderer extends DefaultTreeCellRenderer{
     public Component getTreeCellRendererComponent(JTree tree, Object value,
          boolean selected, boolean expanded, boolean leaf, int row,
          boolean hasFocus) {
          try
               DefaultTreeCellRenderer treeCellRender = (DefaultTreeCellRenderer)
               super.getTreeCellRendererComponent(tree, value, selected, expanded,
          leaf, row, hasFocus);
               DefaultMutableTreeNode node =(DefaultMutableTreeNode)value;
               if(node.getLevel() == 1) treeCellRender.setIcon(getImageDepartment());
          catch (Exception e)
               System.out.println("HelpTreeRenderer Inner Class WIP Viewer Exception " + e.getMessage());
          return this;
}

Similar Messages

  • Problem with JTree editing icons

    Hello,
    I want to edit another icons than the default icons in JTree object.
    I look in the javadoc at the several methods, but I do not find a method witch can give me the possibility to setup the collapsed and expanded icon.
    If some one now how to do that, it will be cool.
    Thanks.

    I write this class :
    public class SampleTreeCellRenderer extends TreeCellRenderer
    /** Font used if the string to be displayed isn't a font. */
    static protected Font defaultFont;
    /** Icon to use when the item is collapsed. */
    static protected ImageIcon collapsedIcon;
    /** Icon to use when the item is expanded. */
    static protected ImageIcon expandedIcon;
    /** Color to use for the background when selected. */
    static protected final Color SelectedBackgroundColor=Color.yellow;
    static
         try {
         defaultFont = new Font("SansSerif", 0, 12);
    } catch (Exception e) {}
         try {
         collapsedIcon = new ImageIcon("images/collapsed.gif");
         expandedIcon = new ImageIcon("images/expanded.gif");
         } catch (Exception e) {
         System.out.println("Couldn't load images: " + e);
    public SampleTreeCellRenderer() {
    super();
    public SampleTreeCellRenderer(String collapsedImagePath,String expandedImagePath) {
    super();
         try {
         if (collapsedImagePath!=null) collapsedIcon = new ImageIcon(collapsedImagePath);
         if (expandedImagePath!=null) expandedIcon = new ImageIcon(expandedImagePath);
         } catch (Exception e) { System.out.println("Couldn't load images: " + e); }
    public void setCollapsedIcon(String path) {
    try {
    if (path!=null) collapsedIcon=new ImageIcon(path);
    } catch (Exception e) { System.out.println("Couldn't load images: " + e); }
    public void setExpandedIcon(String path) {
    try {
    if (path!=null) expandedIcon=new ImageIcon(path);
    } catch (Exception e) { System.out.println("Couldn't load images: " + e); }
    /** Whether or not the item that was last configured is selected. */
    protected boolean selected;
    public Component getTreeCellRendererComponent(
    JTree tree, Object value,     
    boolean selected, boolean expanded,
    boolean leaf, int row, boolean hasFocus) {
         Font font;
         String stringValue = tree.convertValueToText(value, selected,expanded,leaf,row,hasFocus);
         /* Set the text. */
         setText(stringValue);
         /* Tooltips used by the tree. */
         setToolTipText(stringValue);
         /* Set the image. */
         if(expanded) { setIcon(expandedIcon); }
         else if(!leaf) { setIcon(collapsedIcon);}
    else { setIcon(null);}
         /* Update the selected flag for the next paint. */
         this.selected = selected;
         return this;
    public void paint(Graphics g) {
         super.paint(g);
    } // end of class SampleTreeCellRenderer
    I test it but I do not understand why it do not display the icons.

  • Remove collapse and expand icons from tray header

    Hi all
    Is it possible in any way to remove the collapse and expand icons from the tray header, and have the menu icon aligned with the end of the underline?
    Uploading a transparent gif does'n help, because the collaps and expand icon has the same width and heigh as the menu icon. Thus if I upload a transparent gif, and the width of the icons is set to 14px, the menu icon is not aligned with the line which underlines the whole header. There is 14px of blank / transparent.
    Removing the menu icon is easy, all I have to do is deselect all the 'show xxx' options in the iView editor.
    It should be possible to remove the collaps and expand icons, and still be able make it look good.
    Has anyone else had this problem??

    Amit,
    Thank you for replying twice, much appreciated.
    I am sorry for my late response. Thank you for the tip, but as far as I can see this is related to SP 15. We are currently on SP13. I should have of course have mentioned which SP in my problemdescription, and had we been on SP 15 I would have tried this solution.
    Anyway, points rewarded for being helpful.
    Markus,
    I did not find a solution for our problem. However during this summer our customers have decided that it was not very important to remove this icon, so I have left it. I hope the suggestions from Amit and Prem can give you some tips if you have a similar problem.
    Prem,
    as far as I understand you are suggesting to override the jsp for the iViews-trays, like you suggested for the detailed navigation? Anyway, it sounds like a good idea, and worth a try. But, as I mentioned above, we have deceided not to remove the icon. However, it sounds interesting, and I would like to investigate these possibilities when I have the time. points rewarded for being helpful
    Kind regards,
    Reidun
    Message was edited by: Reidun Mongstad

  • ADF TreeTable - How to hide Disclose/Expand icon for leaf node

    We are using ADF Tree Table in our application.
    Whenever a node is expanded - all the child nodes have the disclose/expand icon along with it.
    But, we don't want to show the disclose/expand icon if it is a leaf node.
    How can this be done?
    JDeveloper Version: JDeveloper 11.1.1.3
    Thanks,
    Navaneeth

    I have a hierarchical tree based on single POJO based class exposed as data control.
    (i.e) a node can have many levels.
    Can you specify how we can use the folder icon for this - Can you please provide some detailed information?
    Thanks in advance,
    Navaneeth

  • JTree Expanded By Default

    Hi,
    I was wondering if there is a way to have a tree created and rendered in the completely expanded form. I am thinking along the lines that is there is a setting or a method that by default does it.
    If i am not mistaken there is a posting here in the forum to do this programatically.
    Thank You,
    -Uday

    Did you search for "JTree Expanded By Default" and saw that the answers were all about expanding the tree programatically:
    http://forum.java.sun.com/thread.jspa?forumID=57&threadID=774838
    and you wanted to make double-sure there was no other way to do it?

  • Af|tree::expanded-icon issue ?

    af|tree::expanded-icon
    content: url(/skins/mycompany/skin_images/expand.gif);
    width:16px;
    height:16px;
    i recieve error at af|tree::expanded-icon line (on second COLON':').Css file does not accept this identifier there ? i have tried many ways but all in vain.
    is there any thing special i need to import for new af|tree styles? I am using JDev 10.1.3.3

    Hi
    First of all see if your af:dialog has the contentDelivery="lazyUncached" . This way your popup would not be cached.
    If this is not the solution , then try:
    tree.getDisclosedRowKeys().removeAll();This will remove all disclosed rowKeys.
    A.Gruev

  • Change Table of Contents Expander Icon

    Is it possible to change the Expander Icon [>>] to
    actually read "Table of Contents".

    Rh is using Word's default TOC style.
    If you are generating using the project's CSS, or any other CSS, then you are stuck with fixing each document.
    If you generate to a Word template, then open the template and modify the TOC style to be left aligned. I just tried it and it works fine.
    See www.grainge.org for RoboHelp and Authoring tips
    @petergrainge

  • Changing JTree Expand And collapsed Icons

    Hi,
    can anyone tell me how to change the expanded and collpased icons on a JTree, i am using windows look and feel, and i don't know how to change the '+' and '-' icons, the other icons are changed using the DefaulTreeCellRenderer, but i haven't found a way to achieve my goal....
    thanks

    In the beginning of your main method you write :
    try {
         UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
         UIManager.put("Tree.collapsedIcon",new ImageIcon("plus.gif");
         UIManager.put("Tree.expandedIcon",new ImageIcon("minus.gif");
    catch (Exception exc) {
         System.err.println("Error loading L&F: " + exc);
    }And you change the name of the images with the wanted ones.
    Denis

  • JTree custom icon help

    Hi, i am trying to get custom icon for specific nodes of a tree. In my customTreeCellrenderer that extends the default predecessor, i have this function. The problem is that, the icons are not set to the node i want but the node after that node. Anyone got any suggestions as to what i am doing wrong ?
    Thanks, Dave
         public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) {
              ImageIcon error = new ImageIcon("illegal.gif");
              super.getTreeCellRendererComponent(tree, value, sel,expanded, leaf, row,hasFocus);
              DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
              GroupNodeObject obj = (GroupNodeObject) node.getUserObject();
              if(node.getUserObject() instanceof GroupNodeObject){
                   if(obj.isIllegal()){
                        this.setLeafIcon(error);
                        this.setClosedIcon(error);
                        this.setOpenIcon(error);
                   }else{
                        this.setLeafIcon(getDefaultLeafIcon());
                        this.setClosedIcon(getDefaultClosedIcon());
                        this.setOpenIcon(getDefaultOpenIcon());
              return this;
         }

    may be the next node is instance of GroupNode!!
    just incase, check the code if the error is assigning the nodes!
    This code looks ok.

  • JTree Node Icons

    Ok i know how to set a icon for all nodes in a JTree but my problem is setting incons for certain nodes. I am trying to Create a UML Training Tool for my degree and i have major trouble here. I can change the icons for all but all i want to do is change them for individual nodes, for example a different icon for an actor to a use case, please please can someone help this beginner.

    You need to subclass DefaultTreeCellRenderer and override the getTreeCellRendererComponent method, like:
    class CustomRenderer extends DefaultTreeCellRenderer {
      public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) {
        super.getTreeCellRendererComponent(tree, value, sel,expanded, leaf, row, hasFocus);      
        if (whatever) setIcon(myIcon);
    }                 Then set the cell renderer for your tree:
    myTree.setCellRenderer(new CustomRenderer());

  • JTree - Parent Icon for children

    Hello,
    I have a JTree that displays Categories (=Parent) and it's content (=Child):
    Cat 1
    Cat 2
    Content 1
    Cat 3
      Cat 3.1
        Content
    ...There are some categories that do not have children, and so their icon is the same as the leaves's icon.
    How can I change the icon of categories who do not have children to a "parent-icon"?
    thanks,

    Inherit DefaultTreeCellrenderer and override getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus). Now you can set the icons individually.
    Tutorial:
    http://java.sun.com/docs/books/tutorial/uiswing/components/tree.html

  • JTree customization icons

    Hello,
    Introduction:
    The hierarchical model is a part of the reality, a lot of real examples could be implemented, however the difficulty is to make the nodes of the Jtree closer as possible to the real model.
    My needs:
    1\I need a JTree which should executed as applet.
    2\the top , the branches, and the leaves should customizable.(I would like to have a special icons for each)
    3\when clicking the user should have a data from a java servlet throught tomcat according to each node.
    4\Internationnalization.
    The actual situation:
    1\I have the tree which executes as applet,
    2\I can customize the leaf only by asigning an icon, according to displayed text for the leafe!!!!!!!!!:(
    what about the top of the tree and the branches?
    also, that will be a reall problem when I will try to make an internationnalization!, isn't it?
    so I need a way to make a difference for displayed text and something like an identificator for the tree.
    3\When clicking a tree node the action is to launch an url for a servlet whith passing the displayed text in the tree as a parameter, then the servlet will display the corresponding document(jsp).
    as it's explained in 2\ that will be a real problem when internationnalizing.
    My Questions:
    1\Is there any way the customize all the icons in a tree?, one by one...
    2\Is it possible to refer to a node with an identificator?, as an internal identificator for the programme.And of course the displayed text will different?
    3\Please, provide my with some working codes sources.
    Thanks and Regards,
    kifwet

    Hi,
    I was working on tree icons last week. I used a tree renderer.
    Something like that :
    JTree tree;
    tree.setCellRenderer(new MyRenderer());
    private class MyRenderer extends DefaultTreeCellRenderer {
              Icon treeCollapsedIcon;
              Icon treeExpandedIcon;
              Icon leafIcon;
              public MyRenderer() {
                   super();
    public Component getTreeCellRendererComponent(JTree tree,
                                                                                              Object value,
                                                      boolean sel,
                                                      boolean expanded,
                                                      boolean leaf,
                                                      int row,
                                                      boolean hasFocus) {
         super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
         if (leaf ) {
                   setIcon(leafIcon);
                   } else {
                        if (expanded) {
                   setIcon(treeExpandedIcon);
                   }else{
                        setIcon(treeCollapsedIcon);
         return this;
    I hope this will help you
    Zauz

  • JTree leaf icon

    Hi,
    I am doing a sort of explorer, with a JTree.
    I know how to change icons for leafs, but sometimes my leafs are indeed branches but without nothing in it (an empty directory).
    so the tree displays it as a leaf. But I would like that the tree displays it with the directory icon (but without the "+" sign).
    How can i do this ?
    Sylvain.

    I haven't such problems...
    Ok. You have to create your custom TreeCellRenderer and set it to the tree.
    IconRenderer myRenderer=new IconRenderer ();
    tree.setCellRenderer(myRenderer);
    class IconRenderer extends JLabel implements TreeCellRenderer
    public Component getTreeCellRendererComponent(JTree tree,
              Object value, boolean sel, boolean expanded, boolean leaf,
              int row, boolean hasFocus)
    setText(value.toString());
    //process value (value represents you tree node content)
    if (!leaf) {
    if (expanded)
    setIcon(new ImageIcon("images/expanded.gif"));
    else
    setIcon(new ImageIcon("images/collapsed.gif"));
    else {
    setIcon(new ImageIcon("images/text.gif"));
    MyObject myObj=(MyObject)value;
    if (myObj.isBranch()) {
    setIcon(new ImageIcon("images/branch.gif"));
    regards
    Stas

  • JTree expand

    Hello,
    I have got a JApplet which uses a JTree.
    When a node has child nodes, i.e. when it could be expanded, I have the following problem:
    If the node is selected (I use TreeSelectionModel.SINGLE_TREE_SELECTION), I can't expand it. However, if it isn't selected, I DO can.
    Does somebody what could be happening?
    Thank you very much
    Sergio Ocio

    Hi,
    I'm using a JTree to display a recursive tree (jdev903preview). This works fine.
    However, I have a few issues and questions regarding expanding the tree
    (the +/- buttons):
    1) If I set rootVisible to true, I see the accessor name in the tree root.
    Setting rootVisible to false solves this. But this also removes the '+'
    buttons of the first visible level in the tree! The user can only expand
    these nodes by doubleclicking the icon. How do I get around this? I don't
    want the accessor to be visible (why would I ever want to expose an internal
    name to the user?), but I do want the '+' buttons.You may want to establish a custom cell-renderer for the Tree and take-out the "text" from the root node. Here's a sample:
    jTree1.setCellRenderer(new JUTreeCellRenderer()
    public java.awt.Component getTreeCellRendererComponent(javax.swing.JTree tree, Object value,
    boolean sel,
    boolean expanded,
    boolean leaf, int row,
    boolean hasFocus)
    java.awt.Component cmp = super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus());
    if (tree.getModel().getRoot() == value)
    setText(""); //you can substitute any text you want here for the root node.
    return cmp;
    2) In the tree, the '+' buttons appear even for nodes which do not have children.
    When the user clicks the '+' in front of an empty node, the '+' disappears, and
    the icon changes from the 'map' icon to the 'leaf' icon. Why does it draw the
    wrong icon and the '+' for empty nodes?This is because, JClient tree is bound to database and without executing individual nodes the binding does not know if the node is a leaf or a parent node. If you want to execute all nodes you may want to set the tree to expand all mode. I believe there's some swing call to "expand all nodes in a tree". BY default JClient only expands the first ViewObject in the hierarchy.
    3) Is it possible to expand the entire tree by default?Again beware of the database query impact here.
    Greetings,
    Ivo

  • JTree changing Icons of leaves of a node

    I have a Jtree with root node as "Project"
    I have nodes as "color", "sports", "food" which in turn have leaves.
    I have to set an Icon "Icon1" for all the leaves of node "color"
    I have to set another Icon "Icon2" for all leaves of node "sports"
    and have to set another Icon3" for all the leaves of node "food"
    How do I go about doing it? Thanks.

    Take a look at the Swing Tutorial, specifically http://web2.java.sun.com/docs/books/tutorial/uiswing/components/tree.html#display. This gives a straightforward example of changing icons (or anything on the node) by using a cell renderer.

Maybe you are looking for

  • Gr/ir account item not cleared

    HI all,            for a PO, we done GR and IR and payment., we have done MR11, and f.13, but still in GR/IR gl it is showing open item only.. how can I clear this line item??

  • Without crating purchase requisition ,shall we block/hold  some budget agai

    Hi All, Is there a way that  without crating purchase requisition ,shall we block/hold  some budget against a wbs. also we are using project level budgeting .for example I want to commit  100 budget without creating any PR/PO. Please suggest. With Th

  • How to work web portal with sap rfc

    Hi, This is prasad my question is my project architecure includes: BEA web portal platform as frontend web methods as the middle ware and SAP CCS the data handling will be done using SAP RFC how to handle the validation of fields in the web portal us

  • How to read values of CRM Activity Survey

    Hi Folks In our CRM 3.1 system, our customizer has customized a Survey when creating af Activity. And it works fine. Now She need a ABAP report, which among other values, is going to write out the values registered in the SUrvey. As far as I can see

  • Several curves with several scales on the same graph

    Hello, I am currently working on a project which include a data acquisition VI. I would like to display two curves with two different scales (0 to 1 and 0 to 200) on the same graph. I have been trying nearly all the options in the properties menu, I