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;
}

Similar Messages

  • 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

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

  • Simple question! Is it possible to have a custom icon for an app part?

    Hi All
    Title says it all: is it possible to have a custom icon for an app part / client web part?
    It used to be straightforward with the previous dev tools, but the ImageUrl was typically to a hive folder (which is obviously out of bounds now).
    I've "Binged" with no joy. None of the samples I've seen have a custom icon.
    So - can it be done?
    Regards
    Nigel

    Hi Nigel,
    Updating the AppIcon.png in Napa
    You can upload a new AppIcon.png in into the /Images folder in the file tree in Napa:
    Updating the AppIcon.png in Visual Studio 20102
    You can update a new AppIcon.png in into the Images folder in your Visual Studio solution:
    Keith Tuomi | Twitter: @itgroove_keith | Blog:
    http://yalla.itgroove.net
    Please click "Propose As Answer" if a post solves your problem or "Vote As Helpful" if a post has been useful to you.

  • Custom icon for module_webappsresultsmap

    As the title says...
    When you make a search on the Google map, the icon that shows where the place  is, is a standard Google Map icon.
    Is it possible to override and add a custom icon for this?
    It would be nice to have it within the tag...
    ie. {module_webappsresultsmap,GoogleKey,width,height,ResultsPage,SortType,Image}
    Or have the image within the web app so that each location has a different icon.

    I tried submitting this same problem as a feature request and/or bug report.
    Unfortunately, and somewhat disconcertingly, the Captivate Bug Report form also doesn't work. No matter how thoroughly I entered my request, I got these error messages:
    The following error(s) must be corrected before this form can be completed:
    Please enter your name
    Please enter your E-mail address
    Please select if it is feature request or the bug report.
    Please select a product
    Please enter the issue description

  • Custom icon for Boot Camp partition on Snow Leopard desktop?

    I have a Boot Camp partition (NTFS) with Windows XP. In Snow Leopard, the partition shows on the desktop with a generic hard drive icon. I'd like to change this to a custom icon, but when trying to paste over the generic icon in the Get Info window, Edit->Paste is grayed out.
    In Leopard, it was possible to have a custom icon for a Boot Camp partition by formatting a thumb drive as FAT32, pasting the custom icon onto it in the Get Info window, booting into Windows XP, and copying two invisible icon files from the thumb drive to the NTFS drive. This would display the custom icon for the Boot Camp partition icon on the Leopard desktop. This doesn't work in Snow Leopard.
    Is it possible to use a custom icon for a Boot Camp partition on the Snow Leopard desktop?

    I don't see this option in Properties for the Boot Camp volume. In any case, I believe the custom icon is set correctly for the C: drive in Windows. I followed he procedure in the second paragraph of my initial post, which I learned from a post over a year ago. I copied the two hidden files .VolumeIcons.icns and ._ File _ to the C: drive. When I boot into Leopard, the correct custom icon for the Boot Camp partition appears on the Leopard desktop. But when I boot into Snow Leopard, only a generic hard drive icon appears on the desktop for that partition.

  • Custom icon for Boot Camp partition?

    I have a Boot Camp partition (NTFS) with Windows XP. In Snow Leopard, the partition shows on the desktop with a generic hard drive icon. I'd like to change this to a custom icon, but when trying to paste over the generic icon in the Get Info window, Edit-->Paste is grayed out.
    In Leopard, it was possible to use a custom icon for a Boot Camp partition by formatting a thumb drive as FAT32, pasting the custom icon onto it in the Get Info window, booting into Windows XP, and copying two invisible icon files from the thumb drive to the NTFS drive. This would display the custom icon for the Boot Camp partition icon on the Leopard desktop. This doesn't appear to work in Snow Leopard.
    Is it possible to use a custom icon for a Boot Camp partition on the Snow Leopard desktop?

    No one knows of any fix for this in Snow Leopard? The custom icon shows up OK when I boot into Leopard, but not in Snow Leopard.

  • Custom Icon for Lync Custom Menus

    We can create custom menus in LYNC Client by setting some  registry values.  But we are not able set custom icons fro the same(instead of default ICON). Is there any to set custom Icon for Custom Menus.
    Thanks in advance,

    No the icon is not configurable via the registry values.

  • Custom icon for my USB flash drive?

    Alright, now I realize I'm probably missing something here, but it's getting away from me here. All I want to do is have a custom icon for my flash drive that will show up on any Mac that I plug it into.
    As it is, I can assign a coustom icon (by doing the old get-info-copy-and-paste-the-icon thingie), but it doesn't show up when I plug it into another Mac. I just get the generic disk icon. What am I missing? This has to be quite simple.

    Trey,
    I may be PITW, but I think the icons used to represent various volumes/devices are (if customized) specific to a system (not the volume/device). Thus you would have to set the custom icon for your flash drive on each system you wanted to see it.
    A WAG: I haven't the slightest idea if it would work for a flash drive, but for a CD one would drag the custom icon (.icns file) to the root level of the CD and rename it .VolumeIcon.icns before burning the CD.
    Lee C
    "The early bird may get the worm but the second mouse gets the cheese." -- Willie Nelson
    See the article Backup::Restore.
    Dual 2.5 Power Mac G5   Mac OS X (10.4.3)  

  • Custom icon for boot camp disk?

    I have a Win XP boot camp disk partition (NTFS file system) on an internal hard drive. I want to use a custom icon for this partition on my OS X desktop. However, when I select the icon of this partition in a Get Info window, the only Edit option that ever appears is to Copy the icon. That is, I cannot paste another icon over it (the Paste option is grayed out).
    Is this due to the partition being Windows? Is there a way other than the Get Info method for applying a custom icon? I'm using 10.5.2, but the same thing happened with 10.5.1, and also using a fresh test account.

    Did you know you could have converted the drive to NTFS within Window (not reformatting and losing everything)? I converted mine from FAT32 to NTFS a few months back, lucky for me I already had a drive icon in OSX so the conversion kept the icon.
    For your case though, do this:
    1) Paste your icon (in the Get Info window) onto a USB thumb drive formatted as FAT32. The name of the drive doesn't matter.
    2) Launch Windows through Boot Camp, Parallels Desktop, or VMware Fusion.
    3) Open the thumb drive in Windows.
    4) Select Folder Options… from the Tools menu, and set it to show invisible files.
    5) Copy the two files .VolumeIcon.icns and ._[cr]File, where [cr] is a carriage return, to the NTFS drive.

  • Custom Icon for application file

    I can make director allow me to have a custom icon for appliacation file.
    In director I have attempted this several times where I have tried to have my appliaction file have an icon.  I have purchased two icon program Candy Bar and Fastincs trying to remedy this problem.
    As you see here I am using an ins file created in Fastincs.  Now here is an image to the path and the icon itself Applipcations/ Adobe Director 11/3 HorseLogo.mac.ins
    So there is the setup now when I complile for my program file I get this.
    See the grey Director icon I don't want that I want the three horse logo.
    I also tried to assign the logo after publishing the file.
    then I drag my icon file in
    The program created in director still wont see the icon file.
    If I use Candy bar (icon application)  I get a  different result. The icon works
    in both finder and on the task bar
    This is exactly what I want.
    I works until I try to move the entire package into an installer program  I am using BitRock.  When I compile the installation program then try to run the application I get the following message
    If I choose ignore the install continues.  But I have no icon.
    I am desperate , weeping , screaming , and almost a lost cause, any help any help at all I could really use.
    Thanks
    Robin aka innish

    Hi Robin,
    I'm more of a PC person rather than Mac. I would recommend you look at the Resource and Icon Editor page at:
    http://collab.directorforum.com/Resource_and_Icon_Editor
    It may fix your icon issue from Director.
    Dean

  • Custom Icon for Windows.exe from a Mac

    It doesn't seem possible to insert a custom icon for a Windows executable when working on Captivate on a Mac, is that right? The documentation (below) seems to gloss over this shortcoming.
    Custom Icon
    You can customize the icon that is displayed for the executable file. Click Browse (...) to add a custom icon for your file. Ensure that the icon file has a .ico extension (on Windows)/.icns (for Mac).

    I tried submitting this same problem as a feature request and/or bug report.
    Unfortunately, and somewhat disconcertingly, the Captivate Bug Report form also doesn't work. No matter how thoroughly I entered my request, I got these error messages:
    The following error(s) must be corrected before this form can be completed:
    Please enter your name
    Please enter your E-mail address
    Please select if it is feature request or the bug report.
    Please select a product
    Please enter the issue description

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

  • Should custom icons for USB appear on other Macs?

    I have a custom icon for my flash / usb drive that doesn't appear in other Mac computers. The default icon appears. I haven't been able to test it on another Leopard Mac.
    Is this regular behavior or not? Is there a way to make other Macs show it? I looked around for info about this and didn't see it. Thanks, guru pals.

    Normal. Stored in launchservices.plist, I think. But it is normal. Not like an MP3, where the album art can be stored on the file.

  • Is it worth it to make custom icons for a custom control/indicator?

    I was making custom icons (well not very custom, but still at least somet ext) for controls and indicators, when I realized that the only times you see them are when you open the control, itself, ot if you hover over it in the project with context help on.
    So the question is:
    Is it worth it to create a custom icon for each custom control you make, if it will be seen only rarely?  (The exception being a cluster, since, in the later versions of LabVIEW, you can actually represent your cluster on the BD as the icon you made for it, so it definitely IS worth it to make an icon for it.)
    Thanks!
    Bill
    (Mid-Level minion.)
    My support system ensures that I don't look totally incompetent.
    Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
    Solved!
    Go to Solution.

    Hooovahh wrote:
    I'd like to add another time that you see the control's icon, is when it is a type def cluster, and you have it as a constant on the block diagram.  Then double click the border to shrink the cluster.  It will shrink to the size of the control's icon.
    I also hardly ever make a control icon.  Only when it is on the palette in a reuse package.
    Yeah,t hat's what I meant in my original post, although you CAN represent a cluster constant on the BD as an icon - but it's just the little thing on the bottom of the typdef'd cluster because it obviously has no actual icon. 
    Bill
    (Mid-Level minion.)
    My support system ensures that I don't look totally incompetent.
    Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.

Maybe you are looking for

  • Audio Jack Output Problem

    When I hear music via iTunes with my Beats Mixr, I hear it louder with the right ear. Neither my Beats nor I have a problem. It comes from my MacBook Pro 13" (Late 2013, 4GB). What do I do?

  • Restoring user accounts from TM?

    I need to reinstall Leopard on one of my internal drives. I have hourly TM backups on another internal drive, with the most recent one from a few minutes ago. I don't want to do a "total restore", because that might restore whatever files have been c

  • Palm centro won't ring

    For some reason my new palm centro won't ring, show any missed calls, or let me check my voicemail at home, even though it shows all bars and appears to have network service. I can, however, do all of these things in other locations. I was on the pho

  • How to add contact to bbm

    how to add contact to bbm

  • High Quality music player for OSX Tiger

    Hi I am looking for some help :- I have recently picked up a second hand imac g5, 1.8ghz, 2gb ram, 160gb hdd, runnning OSX Tiger I am trying to find a decent music player, capable of playing alac & flac, up to 24/96khz I have managed to find somethin