Change icon of a non selected node in JTree

Hello
I have a swing application contening a JTree.
I'd like to know how to change the icon of a non selected node in my tree. I have the information about the node and its path. I try to change userObject information and the icon of the node with the setIcon of (DefaultMutableTreeNode), and reload the node (DefaultTreeModel) but it doesn't work.
Do I have to set the change in my CellRenderer ?
Any advice will be welcome
Anne

If you carefully look at the java tutorial tree, the change is made for all the leaf icon. What I want is to change the icon of a not selected node of my tree while I do other stuff with the other nodes like select, display their contents, drag them ...
the operation of a not selected node is independant from the selection in the tree.
So I still ask how to force a node to reload and take care of the change of his icon.
Anne

Similar Messages

  • 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.

  • Setting custom color for selected node in JTree?

    Hi,
    i want to set my own color for selected node in JTree. i don't want to set for all the nodes...how to set Color for Selected node using TreeCellRender class?
    Thanks
    Mani

    I assume you are not setting a custom tree cell renderer...
    javax.swing.JTree theTree = ...;
    java.awt.Color newBGColor = ...;
    ((javax.swing.tree.DefaultTreeCellRenderer)theTree.getCellRenderer())
        .setBackgroundSelectionColor(newColor);

  • How to select node in JTree without firing event?

    I have got standard situation. JTree in the left panel, and several edit boxes in right panel. Certainly, I have TreeSelectionListener, which on every tree node selection shows corresponding model values in edit boxes.
    I'd like to implement next logic:
    1. Something was changed in any edit box in right panel. Model has been changed.
    2. User clicks on different node in tree.
    3. Dialog "Message was not saved. Save?" with Yes/No/Cancel buttons are shown.
    Yes/No buttons are easy to handle.
    Question is about Cancel. I'd like on Cancel button left all edit boxes in their present state (do not restore values from saved model) and select back node, which wasn't saved.
    Problem is next. If I select node by setSelectionPath or smth like that, but... JTree fires event and my listener receives onTreeItemSelected back, which checks that node wasn't saved and ......
    Who does have any idea, or have done similar tasks? How can I select node and do not allow tree fire event this time?
    Thanks in advance.

    First, as soon as the model changes (when editing any
    combo box) some flag will be set. Now the logic which
    updates the combo boxes will do it only on a change of
    the current node and (this is new) if the flag wasn't
    set. You should have some flag anyway because somehow
    you must determine when to show the dialog, shouldn't
    you?Yes, I have got this logic implemented. But it's only the half :)
    I know exactly when my model has been changed, but if it was changed, i'd like to ask user what to do next - svae/loose changes/cancel
    And on cancel i'd like to select last edited tree node and do not get event from tree at that moment.
    >
    Second way, prevent selecting a new node if that flag
    has been set. You could do this by subclassing
    DefaultTreeSelectionModel and overriding some methods
    (setSelectionPath() et al).Ok. I'll investigate this.
    >
    MichaelThanks.

  • Coloring selected nodes in JTree

    i am currently using setCellRenderer() for highlighting a selected node in my JTree.but when i select another node, the previously selected node loses its highlight.i would like to know of how i could make the highlight in the selected nodes remain persistent.

    I am currently using DISCONTIGUOUS_TREE_SELECTION only. my requirement is that i should be able to select any number of nodes.so i use this selection.
    but at the same time, my highlight in selected nodes should be like a toggle-state.
    if i select an already selected node ( say A), the highlight has to go away.
    and at the same time, th highlight on previously selected nodes (say B, C) should be persistent.
    am currently using TreeSelectionListener. and for rendering am using SetCellRenderer.
    in this scenario, how could my work be accomplished?

  • How to show only all children of selected node in JTree??

    Dear friends:
    I have Two Panels, PA and PB,
    PA has a Jtree as code below, and PB listens to PA,
    I hope to do following,
    If I select a node called A in PA, then Node A's all children such as A1, A2, A3 will be displayed in PB, but not display A1, A2, A3's children such as A3 has C1, C2, C3, C4 & C5, until I select A3 then PB will display only all A3's children: C1, C2, C3, C4 & C5;
    i.e, only populate each ONE level of children of Node A or any node I select, not its grandchildren and its grand-grand children;
    Please help how to do it??
    I tried amny times, failed.
    Thanks
    [1]. PA panel code:
    package com.atest;
         import java.awt.BorderLayout;
         import java.awt.event.MouseAdapter;
         import java.awt.event.MouseEvent;
         import java.util.Enumeration;
         import java.awt.Dimension;
         import javax.swing.JFrame;
         import javax.swing.JPanel;
         import javax.swing.JScrollPane;
         import javax.swing.JTextField;
         import javax.swing.JTree;
         import javax.swing.tree.DefaultMutableTreeNode;
         import javax.swing.tree.TreeModel;
         import javax.swing.tree.TreePath;
         public class DefaultMutableTreeMain extends JPanel {
         protected DefaultMutableTreeNode    top = new DefaultMutableTreeNode("Options");
         protected DefaultMutableTreeNode      selectedNode = null;
         protected final JTree tree;
         protected final JTextField jtf;
        protected Enumeration      vEnum = null;
         private      TreeModel                m;
         protected  DefaultMutableTreeNode      getDefaultMutableTreeNode()  {
              //textArea.getText();
                   return selectedNode;
         protected  DefaultMutableTreeNode setDefaultMutableTreeNode(DefaultMutableTreeNode tt)  {
              //textArea.getText();
                   selectedNode = tt;
                   return selectedNode;
         protected  TreeModel getJTModel()  {
              //textArea.getText();
                   return m;
         protected  TreeModel setJTModel(TreeModel ta)  {
                   m = ta;
                   return m;
           public DefaultMutableTreeMain() {
             setSize(300,300);
             setLayout(new BorderLayout());
             DefaultMutableTreeNode a = new DefaultMutableTreeNode("A");
             top.add(a);
             DefaultMutableTreeNode a1 = new DefaultMutableTreeNode("A1");
             a.add(a1);
             DefaultMutableTreeNode a2 = new DefaultMutableTreeNode("A2");
             a.add(a2);
             DefaultMutableTreeNode a3 = new DefaultMutableTreeNode("A3");
             a.add(a3);
             DefaultMutableTreeNode b = new DefaultMutableTreeNode("B");
             top.add(b);
             DefaultMutableTreeNode b1 = new DefaultMutableTreeNode("B1");
             b.add(b1);
             DefaultMutableTreeNode b2 = new DefaultMutableTreeNode("B2");
             b.add(b2);
             DefaultMutableTreeNode b3 = new DefaultMutableTreeNode("B3");
             b.add(b3);
             DefaultMutableTreeNode c = new DefaultMutableTreeNode("C");
             a3.add(c);
             DefaultMutableTreeNode c1 = new DefaultMutableTreeNode("C1");
             c.add(c1);
             DefaultMutableTreeNode c2 = new DefaultMutableTreeNode("C2");
             c.add(c2);
             DefaultMutableTreeNode c3 = new DefaultMutableTreeNode("C3");
             c.add(c3);
             DefaultMutableTreeNode c4 = new DefaultMutableTreeNode("C4");
             c.add(c4);
             DefaultMutableTreeNode c5 = new DefaultMutableTreeNode("C5");
             c.add(c5);
             tree = new JTree(top);
             JScrollPane jsp = new JScrollPane(tree);
             jsp.setPreferredSize(new Dimension(400,300));
             add(jsp, BorderLayout.CENTER);
             jtf = new JTextField("", 20);
             add(jtf, BorderLayout.SOUTH);
               tree.addMouseListener(new MouseAdapter() {
               public void mouseClicked(MouseEvent me) {
                  TreePath   path = tree.getSelectionPath();
                  DefaultMutableTreeNode      selectedNode = (DefaultMutableTreeNode)path.getLastPathComponent();
                 TreePath tp = tree.getPathForLocation(me.getX(), me.getY());
                 setDefaultMutableTreeNode(selectedNode);
                     System.out.println("Current node selected is (tp.toString()=" + tp.toString());
                     System.out.println("Current node selected is getDefaultMutableTreeNode()=" + getDefaultMutableTreeNode());
                 if (tp != null){
                     jtf.setText(tp.toString());
                      System.out.println("It Has Children as selectedNode.getChildCount()= " + selectedNode.getChildCount());
                            Enumeration vEnum = selectedNode.children();
                                int i = 0;
                                while(vEnum.hasMoreElements()){
                                    System.out.println("2 selectedNode = " +  path.toString() + "  has " + i++ + " Children in vEnum.nextElement(" + i + ") = " + vEnum.nextElement());
                 else
                   jtf.setText("");
           public static void main(String[] args) {
             JFrame frame = new JFrame();
             frame.getContentPane().add(new DefaultMutableTreeMain());
             frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
             frame.setSize(400, 400);
             frame.setVisible(true);
         }[2]. PB Panel code
    package com.atest;
    import java.awt.BorderLayout;
    import javax.swing.JScrollPane;
    import javax.swing.JTree;
    import javax.swing.JPanel;
    import javax.swing.event.TreeSelectionEvent;
    import javax.swing.event.TreeSelectionListener;
    import javax.swing.tree.*;
    import javax.swing.JButton;
    import javax.swing.tree.DefaultMutableTreeNode;
    import javax.swing.tree.DefaultTreeModel;
    import javax.swing.tree.TreePath;
    public class DefaultMutableTreeSub extends JPanel implements java.io.Serializable{
      private JButton removeButton;
      private JButton addButton;
      JTree tree;
      private TreeModel      m;
      protected TreeDragSource ds;
      protected TreeDropTarget dt;
    protected  TreeModel getJTModel()  {
              //textArea.getText();
                   return m;
    protected  TreeModel setJTModel(TreeModel ta)  {
                   m = ta;
                   return m;
    protected DefaultTreeModel model;
    protected DefaultMutableTreeNode rootNode;
    DefaultMutableTreeMain dmm = null;
    JPanel inputPanel  = new JPanel();
      public JPanel SLTreeDNDEditableDynamic(DefaultMutableTreeMain tdnd ) {
        //super("Rearrangeable Tree");
        setSize(400,450);
        dmm = tdnd;
             setLayout(new BorderLayout());
             inputPanel.setLayout(new BorderLayout());
             JPanel outputPanel = new JPanel();
             System.out.println("Sub selectedNode tdnd= " + tdnd);
             tdnd.tree.addTreeSelectionListener(new TreeSelectionListener(){
                  public void valueChanged(TreeSelectionEvent evt){
                  TreePath[] paths = evt.getPaths();
                  TreePath   path = dmm.tree.getSelectionPath();
                  DefaultMutableTreeNode      selectedNode = (DefaultMutableTreeNode)path.getLastPathComponent();
                 DefaultMutableTreeNode itemNode = dmm.getDefaultMutableTreeNode();
                     System.out.println("Sub node selected is dmm.getDefaultMutableTreeNode()=" + dmm.getDefaultMutableTreeNode());
                  model = new DefaultTreeModel(itemNode);
                  tree = new JTree(model);
                  System.out.println("Sub selectedNode paths= " + paths);
                  System.out.println("Sub selectedNode path= " + path);
                  System.out.println("Sub selectedNode = " + selectedNode);
                  System.out.println("Sub itemNode = " + itemNode);
                  tree.putClientProperty("JTree.lineStyle", "Angled");
                  tree.setRootVisible(true);
                   inputPanel.add(new JScrollPane(tree),BorderLayout.CENTER);
             return inputPanel;
         public DefaultMutableTreeSub() {
              super();
    }thanks
    sunny

    Thanks so much, I use your code and import followig:
    import java.util.ArrayList;
    import java.awt.List;
    but
    private static List<Object> getChildNodes(JTree j) {
         Object parent = j.getLastSelectedPathComponent();
         int childNodeCount = j.getModel().getChildCount(parent);
         List<Object> results = new ArrayList()<Object>;
         for (i = 0; i < childNodeCount; i++) {
              results.add(parent, i);
         return results;
    here List<Object> and ArrayList()<Object> show red,
    Is my JDK version problem??
    my one is JKD
    C:\temp\swing>java -version
    java version "1.4.2_08"
    Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_08-b03)
    Java HotSpot(TM) Client VM (build 1.4.2_08-b03, mixed mode)
    Error as follows:
    C:\temp\swing>javac DefaultMutableTreeSub.java
    DefaultMutableTreeSub.java:38: <identifier> expected
    private static List<Object> getChildNodes(JTree j) {
    ^
    1 error
    any idea??
    Thanks

  • JTREE: Custom TreeModel does not update non-root nodes

    I have a JTree that uses a custom TreeModel that wraps over (delegates to) a data class X which keeps track of all its children. The class X maintains its own data structure internally (references to other data objects). It also implements 'equals' and 'hashcode' methods. When the data changes in X, it invokes fireTreeStructureChanged on the TreeModel. (There is a TreeModelListener registered with the TreeModel). This works very well for the root node but not for the other non-root nodes. The JTree correctly calls 'equals' and I can see that equals returns 'false' but for non-root nodes the JTree does not refresh though I can see the underlying data structure has changed.
    I am wondering if I may not have fully & correctly implemented fireTreeStructureChanged as it doesn't seem to do much. Or I may be looking at the wrong place. Any pointers would be appreciated.
    BTW, this question is very similar to one asked years earlier http://forums.sun.com/thread.jspa?threadID=153854 but it didn't help me :(
    Thanks.
    ps: working with jdk1.6.0_06 on WinXP.

    I have a same problem. I got an error "Cannot Update Libray".

  • JTree: How to get the currently selected node

    How do I get the currently selected node in JTree?
    getLastSelectedPathComponent() this method always return the last selected node and not the current one.
    Thanks in advance
    Sachin

    Use
    TreePath selectedPath = tree.getSelectionPath()If your tree allows multiple selections, use
    TreePath [] selectedPaths = tree.getSelectionPaths() this will return an array of all selected tree paths.
    Once you get the tree path, call the treePath.getLastPathComponent(). this should tell you the currently selected node.
    Hope this helps
    Sai Pullabhotla

  • Changing the display names of objects in the JTree

    Hi All;
    Is there a possibility of changing the display name of the nodes in JTree? I mean not the actual name of the JTree object, but only the display name? Is there any method available for that?
    Your help would be greatly appreciated
    Thanks in advance
    Regards Madumm

    If your tree node object has application-specific complexity, you should define a custom tree node class and a renderer for that. Or if you just could use DefaultMutableTreeNode, call setUserObject() method with a new String.

  • Jtree Select node and change leafs icon problem

    Hi All,
    i create a tree and implement a TreeSelectionListener:
    my mission is whenever i select a node i need to change the icon of this node (for now.later i will have to find if it have childrens).
    import java.awt.Color;
    import java.awt.Component;
    import java.util.Enumeration;
    import java.util.NoSuchElementException;
    import java.util.Vector;
    import javax.swing.ImageIcon;
    import javax.swing.JTree;
    import javax.swing.event.TreeExpansionEvent;
    import javax.swing.event.TreeExpansionListener;
    import javax.swing.event.TreeSelectionEvent;
    import javax.swing.event.TreeSelectionListener;
    import javax.swing.tree.DefaultMutableTreeNode;
    import javax.swing.tree.DefaultTreeCellRenderer;
    import javax.swing.tree.TreeModel;
    import javax.swing.tree.TreeNode;
    import javax.swing.tree.TreePath;
    public class TreeView{
         DefaultMutableTreeNode top;
         JTree tree ;
         Color frameColor;
         public static ImageIcon NoTSelIcon;
         public static ImageIcon SelIcon;
        public static String[] name= new String[8];
         public TreeView(Color BackColor) {
              // TODO Auto-generated constructor stub
            top =  new DefaultMutableTreeNode("Diagnostics");
            this.frameColor=BackColor;
             SelIcon = createImageIcon("../Resource/Images/Select.gif");
             if (SelIcon == null)
                 System.err.println("Tutorial icon missing; using default.");
             NoTSelIcon = createImageIcon("../Resource/Images/NotSelc.gif");
               if (NoTSelIcon == null)
                 System.err.println("Tutorial icon missing; using default.");
         public Component createTreeComponents(){
                //Create the nodes.
                 createNodes(top);
            //Create a tree that allows one selection at a time.
            tree = new JTree(top);
            //TREE LISTENERS
            //Treeselction listener
            Handler hObject = new Handler();
            tree.addTreeSelectionListener(hObject);
           //Tree expand/collapse listener
            HandlerExpansionListener hObjectExpan = new HandlerExpansionListener();
            tree.addTreeExpansionListener(hObjectExpan);
    //       tree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
            //set tree background
            tree.setBackground(frameColor);
             tree.setCellRenderer(new OverrideTreeCellRenderer(frameColor,SelIcon,NoTSelIcon));
            return tree;
          private void createNodes(DefaultMutableTreeNode top) {
                 DefaultMutableTreeNode category = null;
                 DefaultMutableTreeNode SubCategory = null;
                 DefaultMutableTreeNode SubCategoryBasee = null;
                 DefaultMutableTreeNode SubSubCategoryBasee = null;
                 category = new DefaultMutableTreeNode("Dfe");
                 top.add(category);
                 //Sub test visible
                 SubCategory = new DefaultMutableTreeNode("Test Visible");
                 category.add(SubCategory);
                 SubCategory.add(new DefaultMutableTreeNode("Son 1"));
                 SubCategory.add(new DefaultMutableTreeNode("Son 2"));
                 SubSubCategoryBasee = new DefaultMutableTreeNode("Test Base");
                 SubSubCategoryBasee.add(new DefaultMutableTreeNode("Grandson 1"));
                 SubSubCategoryBasee.add(new DefaultMutableTreeNode("Grandson 2"));
                 SubCategory.add(SubSubCategoryBasee);
          class Handler implements TreeSelectionListener {
                   public void valueChanged(TreeSelectionEvent arg0) {
                        // TODO Auto-generated method stub
                        System.out.println("treeSelect event ");
                        TreePath trph;
                        trph=arg0.getNewLeadSelectionPath();
                        int count=trph.getPathCount();
                        DefaultMutableTreeNode Selnode = (DefaultMutableTreeNode)tree.getLastSelectedPathComponent();
                        String Name = (String)Selnode.getUserObject();
                        setSelected(Selnode,true);
                        int number_ofnodes=getNodeCountBelow((TreeModel)tree.getModel() , Selnode, false);
                        System.out.println("The Number of nodes under "+Name+"="+number_ofnodes);
                        tree.setCellRenderer(new IconRenderer(SelIcon,NoTSelIcon,frameColor));
          class HandlerExpansionListener implements TreeExpansionListener {
                   public void valueChanged(TreeSelectionEvent arg0) {
                        // TODO Auto-generated method stub
                        DefaultMutableTreeNode node = (DefaultMutableTreeNode)  tree.getLastSelectedPathComponent();
                        if (node == null) return;
                      }     // The inner class
                   public void treeCollapsed(TreeExpansionEvent arg0) {
                        // TODO Auto-generated method stub
                        System.out.println("treeCollapsed event ");
                   public void treeExpanded(TreeExpansionEvent arg0) {
                        // TODO Auto-generated method stub
                        System.out.println("treeExpanded event ");
          /** Returns an ImageIcon, or null if the path was invalid. */
             protected static ImageIcon createImageIcon(String path) {
                  //ImageIcon imcon= new ImageIcon(path);
                  //return imcon;
                 java.net.URL imgURL = TreeView.class.getResource(path);
                 if (imgURL != null) {
                     return new ImageIcon(imgURL);
                 } else {
                     System.err.println("Couldn't find file: " + path);
                     return null;
             DefaultMutableTreeNode newnode;
             public void setSelected(DefaultMutableTreeNode Selnode ,boolean isSelected)
                    Enumeration Enchilds=Selnode.children();//ENUMRATE ALL CHILDS FOR THIS NODE
                 if (Enchilds != null)
                      while (Enchilds.hasMoreElements())
                           newnode=(DefaultMutableTreeNode)Enchilds.nextElement();
                           String NameSel = (String)newnode.getUserObject();
                           setSelected(newnode,isSelected);
             //GETTING THE TREE DEPTH
             public int getNodeCountBelow(TreeModel model, Object node, boolean includeInitialNode)
                 int n = includeInitialNode ? 1 : 0;
                 for (int i = 0; i < model.getChildCount(node); i ++)
                     n += getNodeCountBelow(model, model.getChild(node, i), true);
                 return n;
    import java.awt.Color;
    import java.awt.Component;
    import java.util.Enumeration;
    import java.util.NoSuchElementException;
    import javax.swing.Icon;
    import javax.swing.JTree;
    import javax.swing.tree.DefaultMutableTreeNode;
    import javax.swing.tree.DefaultTreeCellRenderer;
    public class IconRenderer extends DefaultTreeCellRenderer {
         private static final long serialVersionUID = 1L;
         Icon SelectedIcon;
         Icon NotSelectedIcon;
         Color BackgroundColor;
         boolean Selected=false;
         boolean Leaf=false;
         boolean IsItaChild=false;
         DefaultMutableTreeNode SelctedNode=null;
        public IconRenderer(Icon SelIcon,Icon NoTSelIcon,Color Bacground) {
             SelectedIcon = SelIcon;
             NotSelectedIcon = NoTSelIcon;
             BackgroundColor=Bacground;
             setBackgroundNonSelectionColor(BackgroundColor);
        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);
             Selected=sel;
             Leaf=leaf;
             DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
             String s2 = (String)node.getUserObject();
       return this;
    }my problem is :
    when i select a node the the method "getTreeCellRendererComponent"
    start to run on the entire tree from buttom to top and than from top to buttom.
    for me it waste of time because if has say 100 nodes it wont botthers me.
    but i have 20000 nodes and more its take a time.
    and for all this nodes i have to make compares.
    is there a way to force the DefaultTreeCellRenderer to not run the entire tree???
    Thanks

    You need to make sure that your TreeModel interprets your group nodes to be non-leaf nodes (one of the methods in the TreeModel interface is called isLeaf). If you are using a DefaultTreeModel with DefaultMutableTreeNode objects, you can use the askAllowsChildren property of DefaultTreeModel and the allowsChildren property of DefaultMutableTreeNode to control this. See the API for more details:
    http://java.sun.com/j2se/1.4.2/docs/api/javax/swing/tree/DefaultTreeModel.html
    http://java.sun.com/j2se/1.4.2/docs/api/javax/swing/tree/DefaultMutableTreeNode.html

  • Icons on desktop and selections on all menus changed to AAAAAAAA

    If I click on the icons the correct name of the file appears, but if I click anywhere else on the desktop the AAAAA's reappear. All of the desktop icons do this. The number of A's varies with each desktop icon. Also, all of the choices on the menu bar across the top of the screen have changed to AAAAAA. The selection choices for the items all have AAAAA. If I use the restore software cd as the start up disk, the menu bar is normal. I have done disk repair, still have the problem.
    The programs and files all work correctly.
    Any ideas?

    [Why did all of my files and more switch to a AAAA name|http://discussions.apple.com/message.jspa?messageID=9216233#9216233]
    [Menu fonts all turn into boxed capital "A"s|http://discussions.apple.com/thread.jspa?messageID=4395251&#4395251]

  • How to change icons of a JTree node dynamically

    Hi all!
    I want to change icon associated with a node dynamically ( i.e. after the tree has being displayed). How can i achieve this?
    Can any one provide me a sample code snippet.
    Thanks in advance
    Murali

    I have created CustomCellRenderer and i'm calling this class as follows
    tree.setCellRenderer((TreeCellRenderer) new CustomCellRenderer(true));
    The boolean value for the constructor (in this case it's true) will be set to
    a local variable in the CustomCellRenderer class. Then upon clicking a node in the tree the boolean value (true) is set and the icon for that node should be changed as specified in the CustomCellRenderer class.
    When i click on a node all the icons of that tree are disappearing.
    Can any one help me in this issue
    public class CustomCellRenderer
              extends          JLabel
              implements     TreeCellRenderer
    private ImageIcon          grayfolderImage;
    private ImageIcon          greenfolderImage;
    private ImageIcon          bluefolderImage;
    private ImageIcon          redfolderImage;
    private ImageIcon          whitefolderImage;
    private boolean               bSelected;
    boolean logfileDeleted;
         public CustomCellRenderer()
              grayfolderImage = new ImageIcon("C:\\images\\grayFolder.gif");     
              greenfolderImage = new ImageIcon("C:\\images\\greenFolder.gif");     
              bluefolderImage = new ImageIcon("C:\\images\\blueFolder.gif");     
              redfolderImage = new ImageIcon("C:\\images\\redFolder.gif");
              whitefolderImage = new ImageIcon("C:\\images\\whiteFolder.gif");     
         public CustomCellRenderer(boolean logfileDeleted){
              this.logfileDeleted = logfileDeleted;
         public Component getTreeCellRendererComponent( JTree tree,
                             Object value, boolean bSelected, boolean bExpanded,
                                       boolean bLeaf, int iRow, boolean bHasFocus )
              // Find out which node we are rendering and get its text
              DefaultMutableTreeNode node = (DefaultMutableTreeNode)value;
              String     labelText = (String)node.getUserObject();
              this.bSelected = bSelected;
              // Set the correct foreground color
              /*if( !bSelected )
                   setForeground( Color.black );
              else
                   setForeground( Color.red ); */
              // Determine the correct icon to display
              if( labelText.equals( "ioexception001" ) )
                   setIcon( redfolderImage );
              else if( labelText.equals( "ioexception002" ) )
                   setIcon( greenfolderImage );
              else if( logfileDeleted ==true )
                   setIcon( whitefolderImage );
              else if( labelText.equals( "ioexception004" ) )
                   setIcon( redfolderImage );
              else
                   setIcon(bluefolderImage);
              // Add the text to the cell
              setText( labelText );
              return this;
         // This is a hack to paint the background. Normally a JLabel can
         // paint its own background, but due to an apparent bug or
         // limitation in the TreeCellRenderer, the paint method is
         // required to handle this.
         public void paint( Graphics g )
              Color          bColor;
              Icon          currentI = getIcon();
              // Set the correct background color
              bColor = bSelected ? SystemColor.textHighlight : Color.white;
              g.setColor( bColor );
              // Draw a rectangle in the background of the cell
              g.fillRect( 0, 0, getWidth() - 1, getHeight() - 1 );
              super.paint( g );
    }

  • I need to change tree cell render on particular node when it is selected.

    actually the treecell change its icon when it is selected. yhe other cell doesnot changed its icon

    Write your own renderer or extends DefaultTreeCellRenderer. Add something like this to the method
    Component getTreeCellRendererComponent(JTree tree,
                                           Object value,
                                           boolean selected,
                                           boolean expanded,
                                           boolean leaf,
                                           int row,
                                           boolean hasFocus)
        if (selected)
           set the icon to be special icon
        else
           set the icon back to normal
    }

  • Cannot change icon UI property on node in hGrid's tree

    Hi,
    I created region of style hGrid (ID HGridRN).
    Under HGridRN I created region of style tree (ID TreeRN).
    Under TreeRN I have members and I want to set some dynamic property for nodeDef2 member.
    HGridRN
    __TreeRN
    ____members
    ______nodeDef1
    ______childNode1
    ________nodeDef2 <- I want dynamic icon on this node
    ________childNode2
    I try to use next sequence of statements:
    OAHGridBean hGridBean = (OAHGridBean)webBean.findIndexedChildRecursive("HGridRN");
    OAWebBean treeBean = hGridBean.findChildRecursive("TreeRN");
    *if (treeBean != null) {*
    *..OATreeDefinitionBean nodeDef2 = (OATreeDefinitionBean)treeBean.findChildRecursive("nodeDef2");*
    *..nodeDef2.setAttributeValue(ICON_ATTR, new OADataBoundValueViewObject(nodeDef2, "NodeIconAttr", "ComplectVO1"));*
    Setting ICON_ATTR attribute doesn't change the icon in hgrid.
    If fact I can even write nodeDef2.setRendered(false); but the node still exists in UI.
    How to get reference to nodeDef2?
    Edited by: user12086842 on 02.01.2013 5:51

    Hi,
    It looks like, that yout context node V_HOME.1 has no elements ( = no data ), try to fill your context node by some data ( by supply method for example). Or you can try change cardinality of your V_HOME.1 node to 1..n.
    Regards Jiri

  • Context Mapping for Non-Singleton Node

    Hi ,
    I have following context structure
    Node_A
    |     attr 1
    |________ Node_B
                                  attr2
                                  attr3
    Node_B is the child of Node_A.  NOde_B has attributes attr2 and attr3.
    Node_B is a Non SIngleton Node.
    Node_B is mapped to Node_View of the View Controller.
    Node_A had 2 elements. Initially Element 1 is the Lead selection Element for Node A. I get the reference for Node_B using the Lead Selection Path
    NodeA_element1 = Node_A->GET_ELEMENT( ). 
    Node_B = NodeA_element1->GET_CHILD_NODE( 'NODE_B' ).
    Node_B is filled with elements, lets say attr2 = 'Dallas', attr3 = 'Detroit'
    Node_View shows the values Dallas and Detrait since its mapped to Node_B
    Now the Lead selection of Node_A changes to 2.
    I again gett he reference for NOde_B usign the Lead Selection Path (index 2)
    NodeA_element2 = Node_A->GET_ELEMENT( ). 
    Node_B = NodeA_element2->GET_CHILD_NODE( 'NODE_B' ).
    Node_B is now filled with, lets say attr2 = 'Mexico', attr3 = 'Canada'
    Since element 2 is Lead selection for Node A, now, and NodeB is mapped to Node_View, I expect the contents of Node_View to be attr2 = 'Mexico', attr3 = 'Canada' since this is along the Lead Selection of Node_A
    But it stays attr2 = 'Dallas', attr3 = 'Detroit'
    So in a nut shell,  the Context Mapping of the Non Singleton Node  DOES NOT map the Lead selection Path when its parent  , changes in Lead Selection.
    Is this a BUG ?
    Thanks

    Hi Anand,
    There is no bug. See when you are saying
    "Node_B is now filled with, lets say attr2 = 'Mexico', attr3 = 'Canada' "
    I am just not sure how you have filled the data in node B. Because the way u populate node data that way only you can get the data. The way you want to get data you must populate data in this way:
    1. Get Node A instance let say in lv_node_A.
    2. Get Node A element instance (lead selection) in your case lets say in lv_elem_A.
    3. Now get node B instance by lv_elem_A->get_child_node( 'B' ) lets say in lv_node_B.
    4. Create element of lv_node_B and bind it to the node B and also populate the value of attributes.
    Repeat the steps as per your requirement. Also Singleton and Non singleton has nothing to do with this it is all about how the instances will be manged in the memory.
    Look at this sample code and will help you while populating data in nested nodes:
        DATA lo_nd_a TYPE REF TO if_wd_context_node.
        DATA lo_el_a TYPE REF TO if_wd_context_element.
        DATA lo_nd_b TYPE REF TO if_wd_context_node.
        DATA lo_el_b TYPE REF TO if_wd_context_element.
        DATA ls_a TYPE wd_this->element_a.
        DATA lv_test LIKE ls_a-test.
        data lv_btest type string.
      navigate from <CONTEXT> to <A> via lead selection
        lo_nd_a = wd_context->get_child_node( name = wd_this->wdctx_a ).
      @TODO handle not set lead selection
        IF lo_nd_a IS INITIAL.
        ENDIF.
        data count type c.
        data count_i type i value 1.
        do 2 times.
          lo_el_a = lo_nd_a->create_element( ).
          lo_el_a->set_attribute(
          EXPORTING
            name =  `TEST`
            value = count_i ).
          lo_nd_a->bind_element( new_item = lo_el_a
                                 SET_INITIAL_ELEMENTS = abap_false ).
          lo_nd_b = lo_el_a->get_child_node( 'B' ).
          lo_el_b = lo_nd_b->create_element( ).
          move count_i to count.
          concatenate count 'in node b' into lv_btest.
          lo_el_b->set_attribute(
          EXPORTING
            name =  `BTEST`
            value = lv_btest ).
          lo_nd_b->bind_element( new_item = lo_el_b
                                 SET_INITIAL_ELEMENTS = abap_false ).
        count_i = count_i + 1.
        enddo.
    This code will set value 1 and 2 in node A's test attribute. and on change of lead selection between 1 and 2 it will show value of attribute BTEST in node B as 1 in node B and 2 in node B...
    Regards,
    Neha

Maybe you are looking for

  • How can I make apps in a Windows PC

    Hello, i what to make apps for Apple Store but i don't have a Mac or a iOS but I have heard that I can make apps in my computer that has installed Windows 7, is that true ?

  • Playing Ps3 on iMac using a thunderbolt

    i have a ps3 and i am trying to use an iMac as a screen all i have is the thunderbolt to HDMI cable but when i connect them it doesn't work. can anyone help?

  • HFR login in error

    Hi All, I'm using HFR 9.3.1V, I'm able to login to FR studio using admin ID, but while draging a Grid in to report to create a new report it si giving some error: Error: DatasourceIDLogin.LoadDatasourceNames Error: -2147467259 Error Loading Datasourc

  • Popup Backgrounds in Photoshop

    What is the workflow or step by step instruction on how to cut a background into segments and place in a button group in order for the background to show in an Encore Pop Up menu? I have 4 button groups or timelines that i want to use in my pop up me

  • Problem with a key

    I have the new 15" PowerBook since last Monday(the DL-DVD-writer version). But the 'i' key needs more pressure than other keys. It is working but it' s annoying. Is it possible to lift of the key without breaking it? Or is there another common known