Custom Icons with JTree

I am using a CustomTreeCellRenderer to import my own icons for nodes in a tree. The problem is that the icons I have are too big and get 'cut-off' when they are displayed in the tree. Is there a way to make java shrink the icons down to the appropriate size?

I am using a CustomTreeCellRenderer to import my own icons for nodes in a
tree. The problem is that the icons I have are too big and get 'cut-off' when they
are displayed in the tree. Is there a way to make java shrink the icons down to
the appropriate size?The height of the font used for displaying the node text determines the maximum
height of the display area of the node. If I'm not mistaken the text for a node takes
html codes so a "<html><br><br>node text<br><br></html>" could help you
increase the height. Otherwise you have to manually shrink your icons using
the 'paint' program (if you're on a Windows box).
kind regards,
Jos

Similar Messages

  • Custom Icons with FAT32 USB Drive

    Hi
    I want to put a custom icon on a USB drive that's formatted to FAT32.
    When I do this with a Mac OS Extended formatted USB drive, it works fine - the icon is attached to the dive, and appears when the the drive is mounted on another Mac.
    But when I do this with a FAT32 formatted USB drive, the icon works on my desktop, but does not appear when the drive is mounted on another Mac.
    Does anyone have a solution to this problem?
    Thanks for your help.
    Bruno.

    Hmm, error -20 is:
    -20 writErr Driver can't respond to Write call
    I'm not sure why it would be doing that. I've got two PNY brand flash drives and have no problem erasing them under Tiger or Panther. You mention trying to repartition the drive. I suppose it's possible that you can't have more than one partition on a flash drive. Maybe the whole thing has to be one format type. Don't know that for sure, though. I've never tried it.

  • Making custom icons with transparency, and Cover View mode

    I tried making a new icon for a folder, and transparency doesn't seem to be treated the same in Leopard as it was in Tiger.
    Trying to get an object to float onscreen, without a square white background, I tried pasting the following onto the folder's icon at the top of a Get Info window:
    1. one layer of a .psd file
    2. the image Saved For Web in Photoshop (as a GIF), open in Photoshop
    3. the same image saved as a .png, opened in Photoshop
    4. a Photoshop EPS with a clipping path, opened in Photoshop
    5. the GIF file opened in Preview
    6. the .png file opened in Preview
    the results:
    1. the transparency surrounding the object comes out as white
    2. a speckled, purple image with a white background
    3. the same as 2
    4. the same as 1
    5 and 6: the transparency seems to work: the icon on the
    Get Info window loses its white background and the icon floats correctly on the Desktop. But in Cover Flow viewing mode, it completely disappears.
    What am I missing? By the way, the icons for the image files, in Cover Flow, show the white background for the .psd and .png files, but not for the .gif, where the transparency shows correctly. The .gif's icon seems to show the image with a white background in List and Icon view, but only the generic GIF icon in Column view. This all seems strange to me.

    I think you probably discovered the Cover Flow Bug. See this thread and the older one referenced in it as well:
    http://discussions.apple.com/thread.jspa?messageID=6846850
    As for the rest, well, at least you can copy something with a transparency out of Preview and paste it as an icon. Preview and Photoshop seem to me to not play well together with transparencies. I've gotten some VERY strange looking things, going back and forth between them with pngs and tiffs. Don't use gifs, or eps files, but I did notice that Finder does a rotten job coping with Photoshop's alpha channel (especially weird since once upon a time it worked fine, ditto for being able to show thumbs for eps files).
    Francine
    Francine
    Schwieder

  • An Error Occurs When I Go To "Build Properties-- Icon" -- Custom Icon Build Fails

    LV 2011
    Mac OS X 10.6.8
    1. Create a new Build Specification using the Application Builder.
    2. Click on the "Icon" tab.
    The following error occurs:
    Three possible outcomes from here:
    1.  Usually LV2011 hangs when changing this option.  (i.e. "time to Force-Quit LabView" and recover the project)  It hangs after I uncheck the "Use default LabView icon" box, and then select my own custom icon from the file browser that appears.
    If it doesn't hang:
    2.  I build using the default LabView icon.  That build succeeds.
    3.  I build using my own icon (which has worked before in LabView app builds).  That build fails, near the end, with the following error:
    Please tell me how I can help get this working.

    Good questions.
    1. This happens with all projects.  As I mentioned, I get an error box as soon as I select the "Icon" tab in the Build Properties dialog.  After that, it either hangs or fails to build.  This happens with any new or existing project.
    2. I have not built an application with a custom icon with LabView 2011.  Remember I am Mac OSX so I install Application Builder separately from a .dmg file.
    3. I was able to successfully build an application with a custom icon in LabView 2010.
    So, it would seem to me that we should rule out that it's a global bug with LV2011 on Mac OSX (10.6.8).  If you install and make a new project, and attempt to add a custom icon, I would bet you can reproduce this exactly.  The error dialog pops regardless, and everytime.

  • Jtree leaf custom icons

    I created my own class that extands DefaultTreeCellRenderer and overrided the function getTreeCellRendererComponent.For now I see the customed icon on the leaf,but when I touch with the mouse the panel the vision of the leaf comes back to default.I tried to do repaint it's doesn't help me
    May be you have any suggestions?

    ok I did the following code in a previous project to handle a similer requirement
    It s from a large project so I'll only post a small part and hope that you can understand it
    If you dont just let me know which part
    package lrmk.client.nav;
    import lrmk.client.*;
    import lrmk.client.wnd.*;
    import javax.swing.tree.*;
    import java.awt.*;
    import javax.swing.*;
    public class NavCellRenderer implements javax.swing.tree.TreeCellRenderer
       DefaultTreeCellRenderer form_window  =  new DefaultTreeCellRenderer();
       DefaultTreeCellRenderer dialog_box   =  new DefaultTreeCellRenderer();
       DefaultTreeCellRenderer table_window =  new DefaultTreeCellRenderer();
       DefaultTreeCellRenderer custom =  new DefaultTreeCellRenderer();
       DefaultTreeCellRenderer def  =  new DefaultTreeCellRenderer();
       public NavCellRenderer(){
          form_window.setLeafIcon(ClientGlobals.getImageIcon("lrmk/client/images/form_icon.gif"));
          dialog_box.setLeafIcon(ClientGlobals.getImageIcon("lrmk/client/images/dialog_icon.gif"));
          table_window.setLeafIcon(ClientGlobals.getImageIcon("lrmk/client/images/table_icon.gif"));
       public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
          TreeCellRenderer r = def;
          NavNode nn = null;
          if (value instanceof NavNode)
             nn = (NavNode)value;
          if (nn != null && nn.getIcon() != null)
             r = custom;
             custom.setLeafIcon(nn.getIcon());
          else if (value instanceof WindowNavNode)
             WindowNavNode wnn = (WindowNavNode)value;
             if (CDialogBox.class.isAssignableFrom(wnn.getWndClass()))
                r = dialog_box;
             else
                String name = wnn.getWndClass().getName();
                name = name.substring(name.lastIndexOf("."));
                if (name.startsWith(".Frm"))
                   r = form_window;
                else if (name.startsWith(".Tbw"))
                   r = table_window;
          return r.getTreeCellRendererComponent(tree,value,selected,expanded,leaf,row,hasFocus);
    }

  • Trouble with some documents: no custom icon, only generic appears

    I tried anything: rebuilt launch servcice, permission repair, daily, weekly, monthly scripts (using maintanace, onyx, etc...) BUT all the documents associated with Openoffice have no custom icon. I also tried reinstalling oo with no success. It happens with textedit and keynote (using "get info", open with, apply to all) and don't know why?
    Can anybody help me?
    Thanks!

    You could create a new admin user and move the data within each of these folders to the corresponding folder on the new account: Desktop, Documents. Library, Movies, Music, etc. You can di it most easily IMO, by copying your Home folder to DVD first. Alternatively, you could use Users/Shared for the data.
    But it would really be best to sort this issue in your present user.
    It would be a good idea to test with a new user though to see if the problem exists there.
    Create a new account, name it "test" and see how your OO & TE work in that User acct? (That will tell if your problem is systemwide or limited to your User acct.) This account is just for test, do nothing further with it.
    Open System Preferences >> Accounts >> "+" make it an admin account.
    Let us know and we'll troubleshoot this further.
    -mj
    [email protected]

  • Custom Icon goes with usb peripheral from Mac to different Mac

    Okay, so I can change the icon on my usb flash drive to show a custom icon each time I plug it into the same Mac day after day, but what if I want to change to a different computer, say my Mac at home, the icon comes up as the default icon. Can I lock the icon so that it will appear the way I want on any Mac I plug it into?

    I took a look at the Adobe PS CS CD, and it did the same thing I do with some of my internal drives, namely, it has a custom icon on the CD ".VolumeIcon.icns" which displays when the CD mounts, just as my own ".VolumeIcon.icns" custom icons do for internal drives. However, when I added a custom .VolumeIcon.icns to my firewire drive the custom icon did NOT display. I tried quitting the Finder and relaunching it, no custom icon. Shutdown the computer and the firewire drive, next time I restarted the firewire drive and it mounted it was still displaying the regular firewire drive icon. Don't know if USB drives would behave like my firewire drive or like a CD, but I expect they will behave like the firewire drive.
    Francine
    Francine
    Schwieder

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

  • Is there a way make a full width menu that opens with a custom icon like the link below?

    I've been trying to make a hamburger menu that just has a custom icon to open revealing the sections of my site with links.
    Huge. Digital agency. Digital business, design, marketing, technology
    Anybody got any tips?
    Thanks

    You can use a lightbox composition

  • Attachments with custom icons

    If I attach an item with a custom icon to a new message, that custom icon is dropped. Any way of preventing that?
    Comments appreciated.

    @Petteri_Paananen,
    While exporting your AIR application..You will be asked whether to include files or not..(Include Files window appears) in which you need to make sure that they are checked.
    Please refer to the screenshot..
    Thanks,
    Bhasker

  • Can't publish with custom icons

    Whenever I attempt to publish an AIR app for which I've selected a custom icon, I get an error message, "An attribute or element contains an invalid value in the application descriptor file. (application.icon.image128x128)"
    Looking in the file "TL Report processor-app.xml" which is created alongside the app, I see that where presumably the path to the icon file should be, I see:
    <image128x128>AppIconsForAIRPublish/AM initials.png</image128x128>
    instead of the complete path to the PNG that I entered in the Publish settings.
    What the f@*# gives?

    Hi Cj
    There are a zillion threads on this general problem so you will find plenty of detailed ideas and fixes if you need to go digging. But your problem sounds like one I have from time to time even with 1.1.1. My fix has been to delete the notorious prepublishstate file from the domain package for your iweb site, and then to make minor changes to the pages where comments are not showing. Then republish your site and bingo there they are.
    If I have spoken too much in code and riddles and you want to try this fix but need more precise details, just let me know.
    Regards

  • Toolbar: replace SAP icon with custom icon

    Hello,
    in the account overview (component BP_HEAD, view BPHEADOverview), the implementation class (CL_BP_HEAD_BPHEADOVERVIEW_IMPL) contains method IF_BSP_WD_TOOLBAR_CALLBACK~GET_BUTTONS where the buttons for the account overview are collected.
    Here you can check which buttons are used by SAP standard, e.g. for the PDF fact sheet, an icon is added:
    ls_button-icon_src = '/sap/bc/bsp/sap/crm_ppm/w_pdf__s.gif' .
    Now, I wanted to replace the given icon by another, customer-specific icon. I've tried to change the given URL to anything else, however, it didn't work. I even found out that the given URL is not necessary, it even works with this:
    ls_button-icon_src = 'w_pdf__s.gif' .
    ls_button-icon_src = 'i_do_not_exist/w_pdf__s.gif' .
    Thus, I assume that there's some kind of mapping of the icon name (e.g. "w_pdf__s.gif") is mapped to any table entry or whatever hard-coded.
    Does anyone having experience with replacing the icon with a custom-specific one and can provide the necessary steps?
    Regards
    Wolfgang

    Hi Wolfgang,
               You can use below sample code to get corresponding url for any standard sap icon:
    lv_icon = 'ICON_LED_GREEN'.
    *   Convert icon code into URL and prepare bee
        lv_icon = cl_bsp_mimes=>sap_icon( id = lv_icon ).
        lr_image->src = lv_icon.
    Also, all the icons are available in the database table 'ICON'.
    I hope that helps.
    Thanks,
    Rohit

  • Getting Avahi devices to show up in Finder with a customized icon

    We have a device broadcasting out its model name "DeviceX" on the network:
    <?xml version="1.0" standalone='no'?><!---nxml--->
    <!DOCTYPE service-group SYSTEM "avahi-service.dtd">
    <service-group>
    <name replace-wildcards="yes">%h</name>
    <service>
    <type>afpovertcp.tcp</type>
    <port>548</port>
    </service>
    <service>
    <type>device-info.tcp</type>
    <port>0</port>
    <txt-record>model=DeviceX</txt-record>
    </service>
    </service-group>
    According to this thread http://forums.macrumors.com/showthread.php?t=458047, on my Snow Leopard Mac I've copied our DeviceX icon .icns file into /System/Library/CoreServices/CoreTypes.bundle/Contents/Resources . And then I'm supposed to add an entry into /System/Library/CoreServices/CoreTypes.bundle/Contents/Info.plist to map between the DeviceX model and this icon file so this custom icon will show up for our device in Finder. But there aren't any details for how to modify Info.plist to do this. Any help would be appreciated. Thanks!
    Mark

    Thank you VERY much!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    Got it to work.  However, my TOC will not update with the new building blocks.
    Have played and played with it.  Any suggestions?
    Thank you!!!!!!!!!!!!!!!!

  • Problem with custom icon on toolbar (iPhone Beta 6 SDK)

    I created two custom icons, using transparency so they are white lines on a transparent background, to add to a toolbar at the bottom of the screen.
    toolbar.barStyle = UIBarStyleDefault;
    UIBarButtonItem *theItem = [[[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"MyImage.png"] style:UIBarButtonItemStylePlain target:self action:@selector(theAction:)] autorelease];
    On the simulator, this shows properly a white icon on the grayish toolbar. On the device itself, it shows a white box the size of the icon. It still works.

    Problem persists in Beta 7. However a workaround (which might have worked in Beta 6, I don't know) is this: use GIF files with transparency, rather than PNG files with transparency. These display properly on both simulator and device.

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

Maybe you are looking for

  • Itunes (WinXP) Crashes OS when importing CD

    Hi all, My Sister is having a problem importing CDs into iTunes. She has tried importing the Mary J Blige The Essential collection and also the Killers Sams Town recently and its blue screened her laptop and then restarts. It manages to import around

  • Why can I not open up photos that are being text to me?

    Why can I not open up photos that are being text to me?

  • Turning off display

    Is there a way to turn off the iBook display when my external VGA monitor is hooked up?

  • "add and remove projects" problem in eclipse weblogic tool 1.1.3

    Hello, i installed eclipse weblogic tool 1.1.3. When i try to add a project to the server, it cannot even list my java projects. I found out that it only list those dynamic web projects. My question is: is it possible to add java project to server. M

  • Custom field in action

    Hi, My customer wants to capture every action inPa40... against an office order. Can I create custom field or is there any standard reserved field that i may use..pls help..the best way.