JTree Renderer Question

Hi,
i want to change the icon of a particular leaf when the user double click it, but i dont want to change the rest of the other leafs icons i want them to keep the icon they have
can this be posible??
thank you

create your own renderer.
Search for "MyRenderer" on this page:
http://java.sun.com/docs/books/tutorial/uiswing/components/tree.html

Similar Messages

  • Setting a JTree renderer breaks the focus traversal order

    Hello,
    I am not sure what's wrong, but when I set a customize JTree renderer it breaks the focus traversal order of my UI. Can someone tell me what's wrong and also how to prevent it from changing the order of my components?
    For instance, if I have component order 1, 2, 3, 4, 5 to begin with and after I call JTree.setCellRenderer(new SomeRenderer()), the order would change to something like this 1, 2, 4, 5, 3
    To give you an overview of what I am creating, I am customizing a UI that will be plug into JFileChooser to replace the default UI. I know I can create my own FocusTraversalPolicy, but the thing is that I don't know some of my components ahead of time. As long as I can prevent the order change, I think it would be fixed.
    Regards,
    Soot

    Try creating a Short, Self-Contained, Compileable, Executable
    program which has this problem. Right now it would take a
    mind-reader to solve your problem.

  • JTree rendering bug

    A bug exists with JTree rendering where a huge treenode is rendered for no apparent reason. It happens infrequently, but I've noticed that it's happening more frequently since I started using jdk1.4.2.
    This seems to be the only place I can find mention of it : http://forum.java.sun.com/thread.jsp?forum=57&thread=217494
    One of the solutions mentioned was to setRowHeight() on the tree. I don't like it, but it seems to be the only way around the bug at present.
    Does anyone know of any potential problems which might arise from explicitly setting the row height on a JTree?

    I basically need to be able to edit the rendered JTable as normal.

  • JTree custom cell renderer question

    When using a custom cell renderer is their anyway to tell the offset of the current node?
    For example if you have a tree with the parent node "Parent" that has a few children nodes it will look something like this:
    Parent
    |----Child 1
    |----Child 2
    |----Child 3
    So the parent would have an offset of zero. I want to know how to get the childrens offset? If this is possible?
    What I am trying to accomplish:
    I have a JTree as a scrollpane rowHeader. While the main body of the scrollpane is a JTable. I need the tree's nodes to fill the entire width so that it looks like part of the table. I figure the row header width - current node offset should be the width that I will need each node to be. Any help is welcome. Thanks.

    the renderer tells you the row, the tree can get you a treepath for a row
    TreePath getPathForRow(int row)
    That can tell you the depth of the node.

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

    When i expand a jtree node, i am populating the content in runtime. I use model.insertNodeInto() method to insert the nodes. I have a dummy node in the first position so that i can get a +, so that i can expand the jtree node. I am changing the first dummy node to a node i want using model.valueForPathChanged() method. Everything works fine. I have a renderer attached. model.insertNodeInto() calls the getTreeCellRendererComponent() method successfully. But model.valueForPathChanged() is not calling the getTreeCellRendererComponent() by default.
    My questions are:
    1. Can i call the renderer forcefully for valueForPathChanged? If so, how?
    2. Is there a easy way to get + for a node, even though the node has no child? i.e a leaf should have + , so that i can expand.
    3. I tried deleting the first node, and insert a new node in first position. But removeNodeFromParent is calling model.reload() which is causing collapse of my node.

    Best thing to do is implementing your own tree mobel
    or tree node.
    It has a method that should retun the number of
    childs a node has. When it return a value greater
    than zero you will get the + sign.I am implementing my own model. but can you help with the exact method to overload and return a value greater than 0. ?
    Thanks.

  • Experimenting with FCP/ Real time rendering question

    Hello, I am preparing to purchase a Mac Pro and spent some time at the local mac affiliate store playing with FCP and motion.
    In fcp I took two clips and dropped them in the timeline, adding the 3d cube transition, and some filters to both clips.
    I was looking at performance of real time rendering on teh base config of the MP I plan on purchasing.
    I then added another clip above these two, intending on dropping the opacity to further push the RTR (real time rendering). This clip overlapped the transition of the two other clips in v1 and v2.
    When attempting to play the timeline the viewer window now said "Not Rendered"
    My question is:
    Is there a limit to how many tracks can be run under the RTR? Why did I get this message?
    My main reason of the move to a Mac Pro is to get away from constantly pre-rendering.
    Thanks everyone in advance!

    In fcp I took two clips and dropped them in the timeline, adding the 3d cube transition, and some filters to both clips.I was looking at performance of real time rendering on teh base config of the MP I plan on purchasing. I then added another clip above these two, intending on dropping the opacity to further push the RTR (real time rendering). This clip overlapped the transition of the two other clips in v1 and v2.
    <
    Sounds like you know what you're doing and what you expect. A factor that has not been mentioned yet, besides RAM, prefs and drive speeds, is your video format.
    Also, the new rev of FCP is taking advantage of tons of processing overhead, vastly increasing the amount of stuff you can do in real time. However, real time is largely a preview operation, regardless of the machine or system, unless you are using proprietary codecs, such as Media 100, that might be hardware-assisted. Output is almost always a rendering issue, multiple stacked or processed layers require the creation of new media.
    The only way you're going to be able to decide if Macintosh and FCP are right for you is to demo thoroughly and that requires using your own footage.
    bogiesan

  • JTree rendering extra node and leaf icons at the end of the label

    Hi,
    Does anyone know how to add an icon to a JTree node or leaf in such a way that it will be displayed behind the text label?
    In an example:
    - rootnode
    - childnode [icon]
    |- leaf
    + childnode [icon]
    Where -/+ are the default (un)collapse icons
    I'd like to apply this to show additional information by using icons with respect to a node.
    I couldn't find anything on the net besides changing the default open/close node icons, yet that's not what I'm aiming for here.

    use this one.I think it will help u.Gd lk
    tree =new JTree(root);
    DefaultTreeCellRenderer renderer =(DefaultTreeCellRenderer)tree.getCellRenderer();
    renderer.setLeafIcon(new ImageIcon(getClass().getResource("leafimages/3.gif")));
    renderer.setClosedIcon(new ImageIcon(getClass().getResource("leafimages/1.gif")));
    renderer.setOpenIcon(new ImageIcon(getClass().getResource("leafimages/2.gif")));
    renderer.setBackgroundNonSelectionColor(new Color(15,85,134));
    renderer.setBackgroundSelectionColor(Color.YELLOW);
    renderer.setTextNonSelectionColor(new Color(217,227,227));
    renderer.setTextSelectionColor(Color.RED);
    renderer.setHorizontalTextPosition(SwingConstants.LEADING);
    renderer.setHorizontalAlignment(SwingConstants.CENTER);
    tree.setFont(new Font("Tahoma",1,12));
    tree.setBackground(new Color(15,85,134));

  • JTree Renderer/Editor

    I have a custom renderer for my JTree that uses a JPanel with multiple fields within it. I am using the same JPanel for editing as well within a custom editor that extends the DefaultCellEditor. When I select to edit, it edits okay. When I focus away (click elsewhere), the cancelCellEditing() method gets called. The display then shows the original values (before editing). If I select the cell for editing again, it shows the previously "edited" values.
    It looks like the editor values are not getting transferred back to the renderer. Any ideas?
    Gil

    Does it work when you press ENTER before clicking out of the text field?

  • JTree rendering failure : big empy space displayed

    Hello,
    I have a problem using a JTree with jdk 1.5 update 10. I could not find anything in the bug database that seemed to link to this problem.
    I have created a JTree that displays the content of a directory under a root node (displayed). I have created my own renderer to customize the labels and i use a TreeModel to add and remove nodes.
    The problem (possibly a known bug): sometimes (it actually seems to be completely random), the Ttree "fails" rendering one of the label, resulting in a big white space instead of the usual label (icon + file name). Other labels in the tree are displayed correctly. The "big white label" can be selected and correctly links to the file it represents (information about the file is displayed correctly). All in all, everything works perfectly fine except one item is displayed as a big empty label.
    Is there any chance this could be a java bug ? If not is there any way i could know what causes this failure ?
    Regards.
    NB: some friend of mine that is working on a different project has exactly the same problem and can't find a solution either.

    I am having the identical problem and its driving me crazy. This started happening to me after I installed new hard drives and reinstalled the OS. I then transfered all the old settings from the old drive. Everything else seems to work perfectly. If you get anywhere with this let me know.
    Hy
    My goal: To import some pictures into iMovie. Maby
    add ken burns efects to them, add a bit of narration
    and some music, edit everything and export.
    The problem: Let say I use the following method: i
    click Media tab, then i click photos, then i select
    the photo, and in the Photo Settings click apply.
    iMovie then imports the photo, puts it in the
    timeline and then the dark red bar bellow apears (the
    one that would means rendering). The problem is,
    there is no light red getting over it (that would
    indicate rendering in progress). It's the same if i
    click and drag a photo into the clip browser (only
    the dark red is displayed on the bottom of the
    thumbnail). If i try to quit iMovie it warns me that
    rendering is in progress.
    It doesn't matter how big a photo is (i tried
    300x200px, 800x500px, 1500x1000px, 3000x2000px) or
    what format (jpg, tiff, png).
    I tried restarting the application and the sistem. I
    created another user to try if anything changes. I
    erased the preferences. I even tried copying the
    whole application from frend's computer (the same
    version and all). The dark red bar doesn't start to
    fill red (i checked in the terminal how much
    processor does it eat and it's on 7%, so it probablly
    means it's doing nothing)
    I have a 2Ghz, 2GB of ram Macbook 13" Intel core duo.
    I have 67 GB of space left (format: Mac-os extended -
    journaled), running OS-X 10.4.8 and updated to the
    latest updates. iMovie version is 6.0.3 (267.2).
    What else is there to do? Would reinstalling the
    whole sistem help and is there a way to keep all of
    my preferences and mail accounts and contacts, … in
    case i have to do that?
    thx in advance
    Peter
    Macbook 13"  
    Mac OS X (10.4.8)  

  • Preview rendering question

    Hey all, Mike the newbie has more questions
    I imported about 6k images into lightroom and I'm working on organizing them within the collections but my question previews. As I scroll through the library there is a delay in seeing the images as they seem to render realtime.  This seems to impact me more when the library has larger images and I'm scrolling down more.
    I imported the images using the 1:1 previews, would going with standard preview produced a better performance result?
    How about none?  I read the FAQ but it really doesn't address whether the rendering is altered by choosing this the different preview options.
    My second question about previews is there any option to rebuild them, for instance say there is a speed bump with using the standard previews, can I delete the current ones and recreate/rebuild them somehow?

    I imported the images using the 1:1 previews, would going with standard preview produced a better performance result?
    How about none?
    That's strange. There might be some small performance penalty of having 1:1 previews over standard (since they are physically bigger), but it should be marginal. What is your machine specs?
    My guess is either the machine is too slow or your expectations are too high (Lightroom is not speed daemon). Are your sure the previews have actually be built?
    My second question about previews is there any option to rebuild them, for instance say there is a speed bump with using the standard previews, can I delete the current ones and recreate/rebuild them somehow?
    Yes, you can discard 1:1 previews and rebuilt standard. Use the Library>Previews menus.

  • 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 :)

  • Using Dynamic Link for projects cut in Premiere and effects in AE.. Rendering Question..

    Hello,
    So this baffles me. I've been working a lot in Premiere CC lately with ProResHQ green screen material. I send the sequence or individual clips using After Effects by right clicking on the clip in Premiere and selecting Create After Effects Composition...
    So I do my thing and when it comes time to render, I select render from IN to OUT in Premiere and wait. Now here's my question. If I select render in Premiere, it will be very sluggish until I click on the After Effects icon in my dock which brings the app to the foreground again. For some reason, this will dramatically accelerate my render speeds in premiere after I re-select the AE app. Why is this doing this?
    I'm using a new Mac Pro trashcan tower 3.5 clock speed. 64GB ram. Dual D700 graphics card. I am using a USB3.0 drive for my editing and the internal drive on the tower for the scratch. I'm getting a Lacie 1TB little bigdisk thunderbolt2 that will be my prime scratch and video location for future stuff.
    Thanks for your help -
    R

    Generally speaking, there is no 'one & only' proper workflow. Just keep in mind the following:
    - not all effects and transitions are properly translated when travelling from PrPro to AE;
    - in Dynamic Link scenario PrPro communicates with AE projects via single instance of headless AE, which creates a bottleneck. See this good old thread on Dynamic Link workflow, pay attention to Todd's comments;
    - since AE allows to set a DI as a proxy to dynamically linked comp, with reasonable amount of dynamically linked comps in PrPro project you can enjoy the best of both worlds, instantly switching between a DI and dynamically linked comp back and forth with no needs to replace anything in PrPro timeline. Test on your own with which amount of dynamically linked comps setting DIs as proxies still work. For my rig test 30 min sequence built out of 935 dynamically linked comps, which are just source footages in their own comps, hence, the equivalent to rendered DIs set to proxies, takes around 27 hours to render, while 30 min sequence built out of the same 935 source footages renders in real time.

  • 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

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

Maybe you are looking for

  • Eee pc 900 and arch problem with xorg ( i think)

    I have installed arch and i have this provlem.When gdm is going to start after 6 attempts,a message shows up and says that something bad happens and it will try again in 2 minutes I have tryed every xorg server in this forum and wiki,I have add my us

  • Mac Still Crashing After Fresh Install of 10.8.

    Hey everyone I have been struggling to determine the issue with my 21.5-inch, Late 2009 iMac.  It has been crashing frequently so I decided to install the OS from scratch and port over the user files but the system is still crashing and I am not sure

  • Creative Cloud Desktop application installer stalls at downloading

    Hi When I download and run CC installer (CreativeCloudSetup.exe) on Win8 It stalls at about 8% and will not download the files needed.  To clarify I can download the CreativeCloudSetup.exe just fine, but when I run it it stalls when trying to downloa

  • JDeveloper stack trace - what's happened to JDev overnight?

    Hi, It's one of those days. JDeveloper worked fine when I left work last night, load it up this morning and I get this stack trace: java.lang.StackOverflowError      at java.util.HashMap.get(HashMap.java:320)      at oracle.ide.net.URLFileSystem.find

  • Lag on DAQmx continuous Outputs?

    I'm trying to use DAQmx to set up an output that is "continuous".  By that I mean that it would keep going without stop but, I want to be able to control the magnitude of the signal.  I don't know why but when I try to change the output I get a lot o