JTree Icon question

Currently, ALL leaves in the JTree are displayed with a certain icon that looks like a piece of paper. What should I do if I want only leaves at depth 4 to have the piece of paper icon and all the rest to have folder icons even if they are leaves?
Thanks

I guess a custom renderer is in order.
http://java.sun.com/docs/books/tutorial/uiswing/components/tree.html#display

Similar Messages

  • Flashing Finder Icon/ Question Mark on Boot

    Today I left my 1.33ghz G4 Mac Mini turned on whilst I went to the shop.
    When I came back i found it eith a flashing finder icon/ question mark.
    I restarted it and it booted up a grey screen, then after a while the flashing finder icon/question mark.
    I have tried putting in the OSX install disc and holding down the C key to start up using the CD and nothing happen, all I get is the same grey screen and flashing icon.
    I have also tried pressing the X key, and holding it down and restarting to get up the startup disk menu, but again nothing.
    Pressing 'option' key during start up only gets me a blue background with refresh button on the left and right arrow on the right - with no Boot Up CD or HDD Icon.
    I have also tried resetting the PRAM, it resets, but after it hasn't solved my problem, as i am back to square one with the boot screen and icon.
    Any help would be appreciated.
    Thanks,
    big.bad.ben

    I would agree with DP that using a wired keyboard will give better results when holding down the C key. The timing of holding down the C key is tricky, and you might have to experiment with it.
    The question mark means that the Mini can't find a bootable disk. Usually this is because the internal hard drive has enough directory damage that it is not bootable. Usually this can be fixed by reformatting the internal drive or replacing it.
    But if you truly can't boot from the install CD, that suggests a more serious problem with the logic board or RAM memory.
    When you power-up the mini, do you get a series of beeps or light flashes? The pattern of such beeps/flashes is a diagnostic aid to determine what might be wrong. Report back with what pattern you observe.
    Be sure to give the install CD some more tries, varying the timing of holding down the C key. Usually you want to do it right after the startup chime.

  • JTree image question

    I have a question about using images in a JTree.
    I have like 2 parent nodes who both have a lot of child nodes now i know how to get an image for every node but how do i get 1 image for 1 parent with all his children and another image for the other parent with his children.

    It is a programming problem because i dont know how to give echt DefaultMutableTreeNode his own picture. You should think of it like msn when you log in your contacts are in a Tree and your offline contacts have a red icon and online contacts have green one. I need to to the same for my program(chat program). But i can't figure out how but i know how to give alle the DefaultMutableTreeNode's a picture but i cant give individual one's a picture.
    I hope i cleared things up :)

  • Email icon question

    Just got my new 9930 and really like it so far. 
    I have a question about email though. I have 3 different email accounts on the phone. 1 gmail, 1 roadrunner and 1 yahoo. Only the yahoo email icon has an icon on it that let's me know it's my yahoo account. Is there anyway to get an icon or something on the gmail and RR email icons to let me know what's what?
    thx

    The others who "don't" see that stuff are most likely using Firefox which has a built in PDF viewer that doesn't have those capabilities yet.
    Good news is it IS possible to disable the built in viewer and use Adobe Reader as the default.
    They need to type "about:config" in the address bar in Firefox (minus the quotes).
    In the configuration page, there is a search bar at the top. They need to type "js" in the bar. A short list of settings containing "js" will appear.
    One setting is "pdfjsviewer disabled" and the value is "false". Right click it to Toggle it to True.
    Then under Tools>Options, in the Applications tab, scroll down to find Portable Document Format (PDF) and Click on the drop-down arrow in the Action column for the above entry and select the PDF viewer you wish to use (the attached image shows "Use Adobe Acrobat (in Firefox)", and should be "(use Adobe Reader (in Firefox)" for people without Acrobat Pro installed.

  • JTree sizing question...

    Hello:
    I have a JTree for which each cell contains a button. I have written a renderer that renders the button, and I realize that I have to do some special stuff to capture a click on the button. My question is unrelated to all of that.
    The problem is that over time, the labels on my buttons change (and may become longer (wider)), but the tree size does not change. In fact, when I update the button label and the tree is re-rendered the rendering of the button gets "chopped off". I've put the tree in a scroll pane, but this doesn't help - the right side of some of the buttons get cut off to the original tree size. I've tried lots of different variations on setPreferredSize, calling repaint, etc, and am not having any luck. I've put together a demonstration of this behavior in a smallish application that I'm posting here, where I create a 2 node tree with buttons that read "Hi", then I change the button labels to "Goodbye" and re-render. You'll see that the button's are cut off about halfway through the button.
    In case its important - I'm running java version 1.5.0_07 on a 32-bit Linux box.
    Any help would be greatly appreciated. Thanks in advance!
    import javax.swing.*;
    import javax.swing.tree.*;
    import java.awt.*;
    public class JTreeQuestion
      public static void main(String [] args)
        JTreeFrame f = new JTreeFrame();
        f.pack();
        f.setLocation(30, 30);
        //Draws buttons with "Hi" (short string)
        f.setVisible(true);
        ButtonNode.updateString("Goodbye");
        //Draws buttons with longer string, buttons get "cut off"
        f.repaint();
    class JTreeFrame extends JFrame
      JTree tree;
      JScrollPane treeView;
      public JTreeFrame()
        super("My Tree");
        DefaultMutableTreeNode root;
        root = new DefaultMutableTreeNode(new ButtonNode());
        root.add(new DefaultMutableTreeNode(new ButtonNode()));
        tree = new JTree(root);
        tree.setCellRenderer(new ButtonNodeRenderer());
        treeView = new JScrollPane(tree);
        add(treeView);
    class ButtonNode
      public static String str = "Hi";
      public static void updateString(String inStr)
      { str = inStr; }
      String getStr()
      { return str; }
    class ButtonNodeRenderer extends DefaultTreeCellRenderer
      public Component getTreeCellRendererComponent(JTree tree,
                              Object value, boolean sel, boolean expanded,
                              boolean leaf, int row, boolean hasFocus)
        Box theBox = new Box(BoxLayout.X_AXIS);
        super.getTreeCellRendererComponent(tree, value, sel, expanded,
                                           leaf, row, hasFocus);
        DefaultMutableTreeNode jtreeNode = (DefaultMutableTreeNode)value;
        theBox.add(new JButton(((ButtonNode)jtreeNode.getUserObject()).getStr()));
        return (theBox);
    }

    For those who are interested. The DefaultTreeModel has a method named nodeChanged() that tells the tree model that a specific node has changed, and the model re-interprets the cell causing its sizse to change as necessary, so that the full button is rendered now.
    Basically what I did was instead of calling repain, I call a method that I wrote that loops through all the tree nodes, indicates they have changed, then repaint's, and it all works out. My trees are relatively small, so this is fine, but if others face the same problem, you'll probably want to selectively indicate which nodes have changed so the tree model doesn't have to do more work than necessary.

  • JTree icons getting cropped

    Hi,
    I have a JTree in which I show the local file system.
    I set the cell renederer to this:
    private class SourceTreeCellRenderer extends DefaultTreeCellRenderer
                   public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel,
                        boolean expanded, boolean leaf, int row, boolean hasFocus)
                        super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
                        setIcon(FileSystemView.getFileSystemView().getSystemIcon(((TreeFile)((DefaultMutableTreeNode)value).getUserObject()).getFile()));
                        return this;
    And I can see the normal windows icons (folder, word file etc).
    It works OK but some of the icons do not show fully , they are cropped or cut-off at the bottom.
    I've tried lots of different things like tree.setRowHeight() and setting the size of the DefaultTreeCellRenderer but nothing works.
    Any Ideas?
    Thanks,
    Jim

    Thanks for your reply Denis.
    I've just found out that my app works fine when I have my DPI setting set to Normal size (96 DPI).
    (I can alter this setting via Control Panel/display/settings/advanced/general.)
    But if the DPI is set to 120 I get the problem.
    I need the app to be able to work properly for both DPI settings.
    Could you maybe change your DPI to 120 and try your app to see if you get the same problem ?
    Anyway, Thanks again,
    Jim

  • JTree icons render as defaults when popup is shown

    I'm having trouble with JTree. When I right click to show a popup, the JTree nodes are not renderered with the icons that I sent in my specialized renderer. Instead they have the default icons. When the popup disappears they revert back to my special icons. I have a specialized renderer, and editor attached to the tree. I have tried turning of the editor, but it still happens. Has anyone seen this before?
    I looked in the DefaultTreeCellEditor, to see if where it was getting the icon, and I found determineOffset() method that calls getLeafIcon(), getOpenIcon(), and getClosedIcon() which are set to the defaults. My tree is more complex that leaf, open, closed icons. Some leaves have different icons depending on their type. I was wondering if somehow it was getting those icons from there.

    Are your treeCellRenderer, treeCellEditor extends from the DefaultTreeCellRenderer / Editor ?
    If yes, you can overwrite those methods.
    There are also the UI manager can force the default icons used.

  • Seting the default JTree 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.

    There are two common ways to change icons:
    1. If you want to adjust icons for a specific tree, use the DefaultTreeCellRenderer methods:
    setLeafIcon
    setOpenIcon
    setClosedIcon
    Of course, you can get the renderer using the JTree Method:
    getCellRenderer
    2. To change the look-and-feel globally, use the UIManager method put, for example:
    Icon yours = . . .;
    UIManager.put("Tree.leafIcon", yours);
    UIManager.put("Tree.openIcon", etc...);
    UIManager.put("Tree.closedIcon", etc...);
    //now create JTree's--Nax                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • JTree event question

    Hi,
    I am facing a problem and hoping somebody here can give me a clue.
    I have a JTree in my application, which has different types of nodes (all implement TreeNode ). One node there needs lazy-loading, what I want is when user clicks either '+' or folder icon/label then this node gets updated. I have added MouseListener to the tree, it works fine with clicking folder icon or label but not for clicking '+'. I also tried adding other listeners like TreeWillExpand etc. but it not seems a good solution to me since I just need to treat one node defferently.
    There are a couple of options I think can help:
    - catch clicking '+' event for specific node
    - display '+' even folder has no child (just for one node)
    - or disable '+' for this node
    Thank you in advance

    Well, after you expand row 1, the row count isn't 6 anymore, is it? It's something larger than that, depending on how many children the first node has.

  • Setting JTree icons

    Hi there,
    I'm working on a sample JTree project where I wanted to render my own icons for open/closed folders and leaf nodes. So I subclassed DefaultTreeCellRenderer and used the inherited ods to set the appropriate icons: setClosedIcon(), setOpenIcon(), and setLeafIcon().
    When I run the program I don't get any error messages and the icons don't show either. I don't get it! Could someone look at the code and tell me where I went wrong?
    Thanks,
    Alan
    import java.awt.*;
    import javax.swing.*;
    import javax.swing.tree.*;
    import java.net.*;
    public class MyTreeCellRenderer extends DefaultTreeCellRenderer
    public MyTreeCellRenderer()
    setFont(new Font("Monospaced", Font.PLAIN, 12));
    setHorizontalAlignment(SwingConstants.CENTER);
    ImageIcon closed = createImageIcon("/images/ClosedFolder.gif", "ClosedFolder");
    if(closed == null)System.out.println("closed is null");
    ImageIcon open = createImageIcon("/images/OpenFolder.gif", "OpenFolder");
    if(open == null)System.out.println("open is null");
    ImageIcon leaf = createImageIcon("/images/Leaf.gif", "Leaf");
    if(leaf == null)System.out.println("leaf is null");
    setClosedIcon(closed);
    setOpenIcon(open);
    setLeafIcon(leaf);
    /** Returns an ImageIcon, or null if the path was invalid. */
    protected static ImageIcon createImageIcon(String path, String description)
    URL imgURL = MyTreeCellRenderer.class.getResource(path);
    if (imgURL != null) {
    return new ImageIcon(imgURL, description);
    } else {
    System.err.println("Couldn't find file: " + path);
    return null;
    import java.awt.*;
    import java.util.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.tree.*;
    public class TestTree extends JFrame
    JTree tree;
    public TestTree()
    super("Tree Test Example");
    setSize(300, 250);
    addWindowListener(new WindowAdapter()
         public void windowClosing(WindowEvent e)
              System.exit(0);
    public static void main(String args[])
    TestTree tt = new TestTree();
    tt.init();
    tt.setVisible(true);
    public void init()
    //Build the hierarchy of containers & objects
    String[] schoolyard = {"School", "Playground", "Parking Lot", "Field"};
    String[] mainstreet = {"Grocery", "Shoe Shop", "Five & Dime", "Post Office"};
    String[] highway = {"Gas Station", "Convenience Store"};
    String[] housing = {"Victorian_Blue", "Faux Colonial", "Victorian_White"};
    String[] housing2 = {"Mission", "Ranch", "Condo"};
    Hashtable homeHash = new Hashtable();
    homeHash.put("Residential 1", housing);
    homeHash.put("Residential 2", housing2);
    Hashtable cityHash = new Hashtable();
    cityHash.put("School grounds", schoolyard);
    cityHash.put("Downtown", mainstreet);
    cityHash.put("Highway", highway);
    cityHash.put("Housing", homeHash);
    Hashtable worldHash = new Hashtable();
    worldHash.put("My First VRML World", cityHash);
    //Build our tree out of our big hashtable
    tree = new JTree(worldHash);
    tree.setCellRenderer(new MyTreeCellRenderer());
    tree.putClientProperty("JTree.lineStyle", "Angled");
    getContentPane().add(tree, BorderLayout.CENTER);
    }

    I tried your suggestion as you can see from the code below, however,
    I'm still having the same problem. No icons are appearing in the JTree.
    Could you copy/paste the code onto your system and try it out and let me know the results. To me the code is logical and should work.
    Please advise,
    Alan
    import java.awt.*;
    import java.util.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.tree.*;
    public class TestTree extends JFrame
      JTree tree;
      public TestTree()
        super("Tree Test Example");
        setSize(300, 250);
        addWindowListener(new WindowAdapter()
           public void windowClosing(WindowEvent e)
              System.exit(0);
      public static void main(String args[])
        TestTree tt = new TestTree();
        tt.init();
        tt.setVisible(true);
      public void init()
        //Build the hierarchy of containers & objects
        String[] schoolyard = {"School", "Playground", "Parking Lot", "Field"};
        String[] mainstreet = {"Grocery", "Shoe Shop", "Five & Dime", "Post Office"};
        String[] highway = {"Gas Station", "Convenience Store"};
        String[] housing = {"Victorian_Blue", "Faux Colonial", "Victorian_White"};
        String[] housing2 = {"Mission", "Ranch", "Condo"};
        Hashtable homeHash = new Hashtable();
        homeHash.put("Residential 1", housing);
        homeHash.put("Residential 2", housing2);
        Hashtable cityHash = new Hashtable();
        cityHash.put("School grounds", schoolyard);
        cityHash.put("Downtown", mainstreet);
        cityHash.put("Highway", highway);
        cityHash.put("Housing", homeHash);
        Hashtable worldHash = new Hashtable();
        worldHash.put("My First VRML World", cityHash);
        //Build our tree out of our big hashtable
        tree = new JTree(worldHash);
        ImageIcon LeafIcon = new ImageIcon(ClassLoader.getSystemResource("images/Leaf.gif"));
        ImageIcon OpenIcon = new ImageIcon(ClassLoader.getSystemResource("images/OpenFolder.gif"));
        ImageIcon ClosedIcon = new ImageIcon(ClassLoader.getSystemResource("images/ClosedFolder.gif"));
        DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer();        
        renderer.setLeafIcon(LeafIcon);
        renderer.setClosedIcon(ClosedIcon);
        renderer.setOpenIcon(OpenIcon);
        tree.setCellRenderer(renderer);
        tree.setRowHeight(18);       
        tree.putClientProperty("JTree.lineStyle", "Angled");
        getContentPane().add(tree, BorderLayout.CENTER);
    }

  • ACR Settings icon question

    I am using CS4, but expect that the question applies to CS3 as well. I cannot get rid of the small icon (two horizontal lines with two small upward-pointing arrowheads) at the upper right of the thumbnail as seen in Bridge. This icon means that the raw file has a setting, or has had a setting?
    I have tried to get it to disappear:
    1) White Balance: As Shot,
    2) chosing Camera Raw Defaults, or,
    3) chosing Reset Camera Raw Defaults,
    4) purging the cache for the folder,
    5) there is no label, star, Reject etc.
    I admit that these choices are a little confusing to me. Should I assume that if the icon persists, there is still a setting applied? If so, how do I eliminate any applied setting?
    Thanks very much,
    Sonny

    But the default setting that you applied is gone. Don't do it if you spent hours tweaking the files... This tells you what files have been adjusted, and which ones didn't.

  • Why JTRee icon did not display??

    Hello sir:
    I can use a panel to display JTree's all nodes and their icons independently in a independent JtreeIcon.java;
    but when I put this JTree into another panel, I can see only tree's all nodes and their text strings, but cannot see their icons, if I use Drag and Drop to move these nodes, the icon moved displays its icon, other ones still not display their icon,
    I think I am short of some methiods, can any guru advice??
    Thanks

    Inside every "big" problem, there's a small one trying to escape.
    If you work at it, you will be able to reproduce you error in a small
    example program.

  • Icon question

    I couldn't find a good spot to post this question, so I hope someone sees this and can answer my question.
    I re-installed snow leopard the other day so that I could start this semester fresh and new. But before I did it, I forgot to back up some of the apps I used almost daily. Now most of them I re-downloaded from Apple's Downloads page, and installed the rest. However there is one app I can't find anywhere.
    I don't quite remember the name of it, I thought it was something simple like "FSTICNS" or similar, but I could be way off. Either way it is the MOST simplistic icon maker I have ever found, and now can't find anymore.
    When you opened it up, it was just a cube that would float and spin with a little (X) in the corner to close. If you were to drag a image on the cube, you could then hit the (X) and it would have you save your new image as an ICON. It was AWESOME!!!
    Now of course I haven't used time machine yet, and that is exactly what this was designed to stop from happening. Ugh... If anyone knows of the app I am talking about please, oh please tell me. It was a free and legal download whatever it was.
    THANKS!!!!!

    So, Get Cape.Wear Cape.Fly ?? (ups, possibly wrong hero)
    Regarding the difficulties to find phonebooths with doors nowadays and the not so pleasant temperatures plus snow and wind and all that, made me put cape and pants into my drawer and get out a nice warm blanket
    Have Fun and thanks for the star.
    Stefan

  • JTree Important Question

    Hi All,
    in the JTree, is there a way to change the root handles
    icons, not through the UIManager?
    I need the Changes to apply only for the one instance.
    is there a key for the putClientProperty method?
    a work around through the TreeCellRenderer is possible to
    write, but seems as a bit of a waste.
    10x in advance

    OK. If "handle" means the leftmost icons, that is the little circle with a dash pointing right or down under Java L&F, or either a + or a - in a square under Windows & Motif L&F, they are NOT part of the node display, and so they are not dealt with by a renderer. They are completely L&F dependant (while the leaf, open, closed are renderer dependant, and the L&F just provides some "hint" to the default renderer). It is possible that some L&F would display trees in a completely different way, without handles. So this is the tree UI delegate business, not the renderer's.
    You can set the icons for the application globally by setting UIManager properties Tree.expandedIcon and tree.collapsedIcon. (you knew that already). The good news is that the UI delegate seems to get these icons once sometime when it is created, rather than asking the UIManager each time it needs them.
    I tried
        Object previousExpanded = UIManager.put("Tree.expandedIcon", myExpandedIcon);
        Object previousCollapsed = UIManager.put("Tree.collapsedIcon", myCollapsedIcon);
        tree2 =  new JTree(data);
        UIManager.put("Tree.expandedIcon", previousExpanded);
        UIManager.put("Tree.collapsedIcon", previousCollapsed);.
    There is a tree1 created before and a tree3 afterwards, and it works fine, that is only tree2 get my icons.
    I tried to go a little farther, as I am not sure when the ui delegate might get reset. So I wrote a descendant of JTree to do the job in updateUI.
    public class CustomHandleTree extends JTree {
      // republish ancestor non-default constructors
      Icon expanded = null;
      public void setExpandedIcon(Icon anIcon) {
        expanded = anIcon;
        updateUI();
      // do the same for collapsed
      public void updateUI(){
        Object defaultExpanded = null;
        if (expanded != null)
          defaultExpanded = UIManager.put("Tree.expandedIcon", expanded);
         // collapsed stuff too
         super.updateUI();
        if(expanded != null)
          UIManager.put("Tree.expandedIcon", defaultExpanded);
         // collapsed stuff too
    }It works too, and I can even set the handles dynamically, when clicking on some button. It refreshes properly.
    The bad news is that I found that by trial and error, and have no single line of documentation to explain why it should work.
    Hope it helps nevertheless.
    Regards.

  • JTree#expandRow() Question

    JTree tree;
    //etc...
    1) /** Expand the tree */
    for (int i=0; i<tree.getRowCount(); i++)
         tree.expandRow(i);
    and tree.getRowCount() = 6
    2) /** Expand the tree */
    for (int i=0; i<6; i++)
         tree.expandRow(i);
    My tree has 6 rows, and each row has its own sub-tree hierarchy.
    I wonder why the first case will expand the whole tree, which includes
    the subtrees of each row.
    But in second case, it only expands the first 6 rows in the tree.
    So basically the question is why (1) and (2) have different tree view outputs??

    Well, after you expand row 1, the row count isn't 6 anymore, is it? It's something larger than that, depending on how many children the first node has.

Maybe you are looking for

  • Follow-Up Transaction in WebClient UI

    Hello, I want to create a follow-document in Web UI. Copy Control works in SAP GUI but when I press the button for Follow-Up in Web UI no transaction types are displayed in the PopUp. Any idea of how to solve this? Best Regards JM

  • Cannot update batch header MIGO GR in MB_DOCUMENT_BADI

    I am trying to update next inspection date via MIGO when Goods Receipting a production order which is held in the batch header and in a classification we have set up. I have used function modules to try and perform the update. I have used both 'VB_UP

  • When i mistype a web address my browser shuts down! Why?

    It not only closes the page: it shuts down the entire browser!

  • Itunes quits streaming to appletv in Vista 64

    I have an appletv that I stream music from my vista 64 PC (quad core CPU, 8 gig RAM, terabyte drive) on wired LAN. The problem is that after perhaps an hour of streaming music with no problems the appletv will no longer see the itunes service and the

  • DesignJet T520 plotter - not working since windows update

    Our clients new plotter worked flawlessly until a couple of weeks back when the machines were suddenly unable to print one morning. It turns out that  an optional update for the T520 24" on the affected machines has been applied which has basically k