Using animation as icon for JTree node

Hi,
I am using a custom tree cell renderer. I have a label in the renderer, the label have gif Image Icon, but the problem is it is not getting animated. But when I use a JLabel with gif icon some where else it is working fine, but it is not working for tree node.
package com.gopi.utilities.gui;
import java.awt.Color;
import java.awt.Component;
import java.awt.GridBagConstraints;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTree;
import javax.swing.tree.DefaultTreeCellRenderer;
import javax.swing.tree.TreeCellRenderer;
import com.gopi.remfilebrowser.gui.GUIUtil;
import com.gopi.remfilebrowser.util.FileBrowserConstants;
public class CustomTreeCellRenderer implements TreeCellRenderer
     private JPanel panel;
     private JLabel label;
     private TreeCellRenderer defaultRenderer;
     public CustomTreeCellRenderer()
          super();
          panel = GUIUtil.createGridBagPanel();
          label = new JLabel();
          label.setHorizontalAlignment(JLabel.LEFT);
          System.out.println("New");
          GridBagConstraints gc = new GridBagConstraints();
          GUIUtil.fillComponent(panel,label);
          defaultRenderer = new DefaultTreeCellRenderer();
     public Component getTreeCellRendererComponent(JTree tree, Object value,
                 boolean sel,
                 boolean expanded,
                 boolean leaf, int row,
                 boolean hasFocus)
          if(value instanceof NewAbstractTreeNode)
               NewAbstractTreeNode node = (NewAbstractTreeNode) value;
               System.out.println("dr");
               label.setText(value.toString());
               label.setIcon(ImageLoader.getInstance().getIcon(node.getIconKey()));
               if(hasFocus && sel)
                    panel.setBackground(FileBrowserConstants.TREE_NODE_SELECTED_COLOR);
               else if(sel)
                    panel.setBackground(FileBrowserConstants.TREE_NODE_UNSELECTED_COLOR);
               else
                    panel.setBackground(Color.white);
               return panel;
          return defaultRenderer.getTreeCellRendererComponent(tree,value,sel,expanded,leaf,row,hasFocus);
}

JLabels using ImageIcons are designed to display the icon as is, including animation and all.
A CellRenderer only paints the Icon once, when the cell is painted. Much ike a rubber stamp of the JComponent. Hence, its not designed to do the animation and all.
If you really want it, you can probably use MediaTracker and a Timer to do your animation scheduling. Might not be very pretty code though
ICE

Similar Messages

  • Unable to display blinking icon for JTree

    I am unable to see blinking icon for JTree node. If I use any other image which is not blinking, then I am able to see icon.
    If blinking image is used, it shows blank image.
    Please refer to following code.
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Component;
    import java.net.URL;
    import javax.swing.ImageIcon;
    import javax.swing.JApplet;
    import javax.swing.JScrollPane;
    import javax.swing.JTree;
    import javax.swing.tree.DefaultMutableTreeNode;
    import javax.swing.tree.DefaultTreeCellRenderer;
    public class TreeApplet extends JApplet {
    JTree tree;
    DefaultMutableTreeNode root;
    DefaultMutableTreeNode node1;
    DefaultMutableTreeNode node2;
    DefaultMutableTreeNode node3;
    DefaultMutableTreeNode node4;
    private ImageIcon errorIcon = null;
    private URL resource = null;
    private static final long serialVersionUID = 1L;
    public void init() {
         errorIcon = loadIcon("images/errorBlink.gif");
         root = new DefaultMutableTreeNode(new ProcessInfo("root", "error"));
         node1 = new DefaultMutableTreeNode(new ProcessInfo("Node1", "info"));
         node2 = new DefaultMutableTreeNode(new ProcessInfo("Node2", "warn"));
         node3 = new DefaultMutableTreeNode(new ProcessInfo("Node3", "debug"));
         node4 = new DefaultMutableTreeNode(new ProcessInfo("Node4", "error"));
         node1.add(node2);
         node3.add(node4);
         root.add(node1);
         root.add(node3);
         setLayout(new BorderLayout());
         tree = new JTree(root);
         tree.setCellRenderer(new TreeRenderer());
         add(new JScrollPane((JTree) tree), "Center");
    private class TreeRenderer extends DefaultTreeCellRenderer {
         private static final long serialVersionUID = 1L;
         public TreeRenderer() {
              this.setBackgroundSelectionColor(Color.lightGray);
              this.setBorderSelectionColor(Color.BLACK);
         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);
              setIcon(getStatus(value));
              return this;
         private ImageIcon getStatus(Object value) {
              DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
              ProcessInfo nodeInfo = (ProcessInfo) node.getUserObject();
              String status = nodeInfo.getStatus();
              if ( status != null ) {
              if ( status.equalsIgnoreCase("error") ) {
                   return errorIcon;
              return null;
    private ImageIcon loadIcon(String name) {
         ImageIcon icon = null;
         resource = this.getClass().getResource(name);
         if ( resource != null ) {
              icon = new ImageIcon(resource);
         return icon;
    }

    1. Use code tags to post codes -- [code]CODE[/code] will display asCODEOr click the CODE button and paste your code between the {code} tags that appear.
    2. A renderer is just a "rubber stamp" used to paint on the table/tree/list/whatever. You can't display animation in an ImageIcon by setting it to a renderer. Since the JLabel subclass used as the renderer isn't a part of any visible component hierarchy, the icon won't be refreshed with new frames.
    db

  • How to Use different icons for JTree in the same level

    Hi guys, i come cross a problem with JTree. The module need a JTree which need to represent items in the same level using different icons. For example:
    [Icon for Root]Root
    |
    |_____________[Icon for Table] TABLES
    |
    |_____________[Icon for Index] INDEXS
    |
    |_____________[Icon for Views] VIEWS
    As i know, the default behavior for JTree is using the same icon for all leaves and
    the same icon for all node that has children. How can i achieve that?
    Thansk a lot!

    subclass DefaultTreeCellRenderer. if you overwrite the method below, then you can set the icon to whatever you want....!
        public Component getTreeCellRendererComponent(JTree tree, Object value,
                                    boolean sel,
                                    boolean expanded,
                                    boolean leaf, int row,
                                    boolean hasFocus) {
         String         stringValue = tree.convertValueToText(value, sel,
                               expanded, leaf, row, hasFocus);
            this.tree = tree;
         this.hasFocus = hasFocus;
         setText(stringValue);
         if(sel)
             setForeground(getTextSelectionColor());
         else
             setForeground(getTextNonSelectionColor());
         // There needs to be a way to specify disabled icons.
         if (!tree.isEnabled()) {
             setEnabled(false);
             if (leaf) {
              setDisabledIcon(getLeafIcon());
             } else if (expanded) {
              setDisabledIcon(getOpenIcon());
             } else {
              setDisabledIcon(getClosedIcon());
         else {
             setEnabled(true);
             if (leaf) {
              setIcon(getLeafIcon());
             } else if (expanded) {
              setIcon(getOpenIcon());
             } else {
              setIcon(getClosedIcon());
            setComponentOrientation(tree.getComponentOrientation());
         selected = sel;
         return this;
        }

  • How to display different icon, for different node of jtree

    Hi All,
    How to display different icon, for different node of jtree

    you haven't responded to my last post here: [http://forums.sun.com/thread.jspa?threadID=5323190&messageID=10382676#10382676|http://forums.sun.com/thread.jspa?threadID=5323190&messageID=10382676#10382676]

  • Animated gif icon for an exception instead of the standard icon?

    Hello,
    is there a possibillity to use an animated gif icon for an exception instead of the red standard icon in a web template?
    I tried  to change the standard icon s_s_ledr.gif against an animated gif icon in the mime repository, but it does not work. In the IE the icon is still shown without animation.
    Maybe I´ve changed the wrong icon?
    Can you please help me?
    Greetings
    Andreas
    Edited by: Andreas Zenner on Feb 25, 2009 1:22 PM

    Hi Andreas,
    it is possible to integrate own symbols for exceptions. If you can use animated gif I don't know. However there is a post over here explaining the usage of the modification for symbols:
    Re: BI 7 Web Design API - Parameter modification - Exception symbol
    If you have questions just let us know.
    Brgds,
    Marcel

  • 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

  • AdvancedDataGrid: display disclosure icon for empty nodes

    Hi,
    I have an AdvancedDataGrid with HierarchicalData that will be loaded lazily. Initialy, the tree displays only the parent nodes. Since the nodes' children are not loaded yet, no disclosure icons are rendered. Is there a way to force the tree to also render the disclosure icon for empty nodes, so that I can load a node's children when it is expanded?
    I have tried looking at TreeDataDescriptors, but AdvancedDataGrid or HierarchicalData don't seem to support this.
    I also looked into extending AdvancedDataGridGroupItemRenderer, but fail to see where I can put logic to render the disclosure icon.
    Any help would be much appreciated.
    Glenn

    Thanks, a case of missing the obvious
    Extending HierarchicalData and overriding canHaveChildren and hasChildren worked.

  • Custom icon for tree node

    Hi,
    Can anyone tell me how to change the icon for a particular node in a JTree?
    I know how to change all the leafs for example by using the DefaultTreeCellRenderer.setLeafIcon()method. But do you know how to set just one node to a particular icon?
    Cheers,
    Jim

    MyTreeCellRenderer extends DefaulTreeCellRenderer{
      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);
        //Do your condition on your value
        if( value ....){
         setIcon(myIcon);
        return this;
    }

  • How do I remove expand / collapse icon for JTree empty folders

    Hi
    I am using a JTree as a file system browser. I use DefaultMutableTreeNode nodes.
    I have a problem with empty folders.
    Empty folders show the expand / collapse icon, leading the user to believe there are sub-directories. When the user double-clicks the folder, the expand / collapse icon goes away. This is a "haha-gotcha" glitch that I really don't want my users to have to continually deal with.
    So, how might I get my JTree to not show the expand / collapse icon for empty folders?
    Thanks
    Wayne

    Maybe I can use the FileSystemView isTraversable(File f) method in my TreeCellRenderer class to check if anything is in the directory.
    But I still need to know how to disable the expand / collapse icon for such a node.

  • Tweaking LAF icons for JTree

    What I want to do, at the moment, is to indicate some JTree nodes as disabled, but this could be a more general question. I realise I can substitute a custome renderer to replace the icons representing tree nodes with an image of my own. But I want the replacements to be consistent in appearance with the standard images used in the Windows LAF, ideally I'd like a coresponding stuff for the metal LAF too.
    So:
    1) Where are the standard bitmaps squirelled away so I can grab and modify them.
    2) Is there a proper way of switching images on the basis of the chosen LAF.

    1) I don't know where they are, but you can get them with (e.g.):
    Icon openIcon = (Icon)UIManager.get("Tree.openIcon");2) You can check the currently installed LAF and then decide which icons you use:
    if (UIManager.getLookAndFeel() instanceof javax.swing.plaf.metal.MetalLookAndFeel) {
      UIManager.put("Tree.openIcon", new ImageIcon(getClass().getResource("resources/images/open.png")));
      UIManager.put("Tree.closedIcon", new ImageIcon(getClass().getResource("resources/images/closed.png")));
      UIManager.put("Tree.collapsedIcon", new ImageIcon(getClass().getResource("resources/images/collapsed.png")));
      UIManager.put("Tree.expandedIcon", new ImageIcon(getClass().getResource("resources/images/expanded.png")));
      UIManager.put("Tree.leafIcon", new ImageIcon(getClass().getResource("resources/images/leaf.png")));
    }After setting such properties you should call
    SwingUtilities.updateComponentTreeUI(<component>);to update the whole component tree starting with <component>. So, <component> often is the applet or the main frame of an application where your ui modifications take place..
    Sources:
    i) LAF-Demos in <java-install-dir>/demo/jfc/Metalworks
    ii) Code example to list LAF-properties in a table (search for "ListProperties"): http://forum.javacore.de/viewtopic.php?p=5682&sid=301abe27a4d5fb3099b130c55a6a52e7

  • How to set icon for JTree

    hi,
    I have a JTree. For this JTree i have a DefaultJTreeCellRenderer.
    i have done like this
    JTree tree = new JTree();
    DefaultJTreeCellRenderer renderer = new DefaultJTreeCellRenderer();
    renderer.setOpenIcon(....);
    renderer.serCloseIcon(...);
    tree.setCellRenderer(renderer);but this is not working.
    how to change the icons of the node when i click
    thank you

    public class Test extends JFrame implements ActionListener {
         private static final long serialVersionUID = 1L;
         private JButton buttonCreate;
         private JTree tree;
         private DefaultMutableTreeNode defaultMutableTreeNode;
         private DefaultTreeModel defaultTreeModel;
         private int i;
         public Test() {
              setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              layoutComponents();
              setSize(400, 400);
              setLocationRelativeTo(null);
              setVisible(true);
         private void layoutComponents() {
              defaultMutableTreeNode = new DefaultMutableTreeNode("Root");
              defaultTreeModel = new DefaultTreeModel(defaultMutableTreeNode);
              tree = new JTree(defaultTreeModel);
              tree.setRootVisible(false);
              buttonCreate = new JButton("Create");
              getContentPane().setLayout(new BorderLayout());
              getContentPane().add(tree, BorderLayout.CENTER);
              getContentPane().add(buttonCreate, BorderLayout.SOUTH);
              DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer();
              ImageIcon icon_close = new ImageIcon("./images/project_closed.gif");
              ImageIcon icon_open = new ImageIcon("./images/project_opened.gif");
              renderer.setOpenIcon(icon_open);
              renderer.setClosedIcon(icon_close);
              tree.setCellRenderer(renderer);
              buttonCreate.addActionListener(this);
         public static void main(String[] args) {
              new Test();
         public void actionPerformed(ActionEvent e) {
              addElementToParent("Child" + i++);
         private DefaultMutableTreeNode addElementToParent(Object theChild) {
              return addElementToParent(defaultMutableTreeNode, theChild, true);
         private DefaultMutableTreeNode addElementToParent(DefaultMutableTreeNode theParent, Object theChild, boolean shouldBeVisible) {
              DefaultMutableTreeNode childNode = new DefaultMutableTreeNode(theChild);
              if (theParent == null) {
                   theParent = defaultMutableTreeNode;
              defaultTreeModel.insertNodeInto(childNode, theParent, theParent.getChildCount());
              TreePath childTreePath = new TreePath(childNode.getPath());
              //          Make sure the user can see the lovely new node.
              if (shouldBeVisible) {
                   tree.scrollPathToVisible(childTreePath);
              tree.requestFocusInWindow();
              return childNode;
    }this is the code which i was trying to execute.
    here i want to explain you is
    when i click the node the icon should change to open_icon
    when i click the other node the previous node icon should change to close_icon
    how is this possible
    null

  • HGrid hide the Action icon for Root Node

    Hi,
    I have a Hgrid developed. It contains a column called "Action" against all the nodes. I need to hide this icon only for the Root Node. Can anyone please suggest a solution?
    Thanks in Advance!
    Cheers.,
    Hem

    You can use a switcher (Icon and messageStyledText) or SPEL (rendered true or false) to resolve this issue. You can add a additional attribute in your VO which controls the SPEL rendered property of the icon or provides a case value for the switcher.

  • Change the default icon for unsatisfied node

    Is it possible to change the default icon for the unsatisfied node (unsatisfied indicator). I have checked the UI content element with the same name, but it does not have the source file setting in it, so I guess it is hard coded. I tried to change the source file with the name unsatisfied_status.gif to a different image and it works, but this will be a system wide change. I want to do this as a model specific change. Has anyone done this before? Thanks in advance.
    Cheers,
    Biju.
    [My Oracle Blog|http://oraclewithbiju.blogspot.com]

    Did you try changing image name in UI edit page?
    UI edit page lists few images which can be changed for each UI, like unsatisfied indicator, logic status icons etc.

  • HT2493 I have a jpg file the image of which I wish to use as an icon for a program.

    when I use the advised strategy of copying its icon to the icon in the info page of the program, I get a change -- but to the generic icon for jpg files, rather than the actual image of the content of the particular file.

    You can convert the jpeg file to an icon file and use that as the image, with this application: img2icns
    Drag the jpg onto img2icns window, save it as an icon. Copy and paste this as per the method you mentioned previously.
    tested to work on 10.6.8

  • Hide disclosure icon for some nodes

    Hi,
    For some nodes with children, I would like hide the
    disclosure icon; for some not.
    How can I do that?
    I tried disclosure._visible = false in the function
    setValue(node, state) of my custom TreeRow Renderer extended from
    mx.controls.treeclasses.TreeRow. It did not work though.
    For other embedded moviclip in a tree, it seems I can
    control, i.e. nodeIcon, cell.
    Thx,
    Guangming

    Thanks, a case of missing the obvious
    Extending HierarchicalData and overriding canHaveChildren and hasChildren worked.

Maybe you are looking for

  • How do I upload videos from an SD card to the movies folder in Finder on my iMac?

    I'm having trouble uploading videos from my SD card to my iMac. I'm wanting to save it in the "Movies" folder in Finder. When I open the SD card on my iMac, I am able to view the videos in QuickTime Player. They were an AVCHD file format. It gave me

  • Need more than 8 Audio Streams - Possible solution

    Referring to this topic (now archived so cannot reply): http://discussions.apple.com/message.jspa?messageID=12870874 Wikipedia DVD entry "DVDs can contain more than one channel of audio to go together with the video content, supporting a maximum of 8

  • I can't sync photos and music to my iPad afternoon updated to ISO5

    After updating to IOS5, i can't upload my photos and music to my dad's iPad.  My and my mom's iPhone 4 are OK.  We just have problem with my dad's iPad. I just updated it to 5.0.1, it's still not working. Anyone has the same problem? And can anyone h

  • Why we use BMV0 transaction

    HI, we use BMV0 transaction for data transfer for direct input method, why we use for direct input method only?, session and calltransaction purpose  is not required? could u clarify it, when we schedule job in sm36, why again scheduling in BMV0 requ

  • Error 5002 when trying to rent

    Anyone else getting this error when attempting to rent a movie? We also get "an unable to connect to itunes" message when attemping to rent a movie from our Apple TV.