JTree making nodes in TreeModel invisible

I have a TreeModel that represents a database structure. I want to display that structure within a JTree. No problem so far, I just create the JTree using theTreeModel. Everything works great.
Now, I want some nodes in the tree (tables in the structure) to not be visible to the user, but I cannot remove them from the model. I need the entire db structure intact within the model so all my processing works correctly, but there is no need for the user to be aware of the entire structure.
Anyway, have any ideas?
Thanks a bunch.

Try extending DefaultMutableTreeNode and just had it
return the count and children of the 'visible' nodes.More info... And maybe add methods getRealChildCount() and getRealChild(int i) so you can manipulate them internally.

Similar Messages

  • JTree delete node

    Have a problem with JTree
    A node I call folderNode will normally contain sub-nodes with names lik subnode1,subnode2,subnode3 etc. (Just examples)
    The folder node will then represent the range, so for one with the mentioned subnodes, name would be "subnode1- subnode3".
    To update this foldername after I have deleted say nr 3, I use "theFolderNode.setUserObject("new name here")), and then treeModel.nodeChanged(theFolderNode); I would then expect "subnode1- subnode2". (Don't mind the method of finding the correct label..)
    If I then try to get the new userObject and checking by typing:
    System.out.println(theFolderNode.getUserObject().toString()); - I actually get out what I want, but the label of the FolderNode is still not updated..
    What am I missing here??

    Here is an excert from an article from javaworld
    "The Java programmer must keep in mind that it is the garbage collector that runs finalizers on objects. Because it is not generally possible to predict exactly when unreferenced objects will be garbage collected, it is not possible to predict when object finalizers will be run. Java programmers, therefore, should avoid writing code for which program correctness depends upon the timely finalization of objects. For example, if a finalizer of an unreferenced object releases a resource that is needed again later by the program, the resource will not be made available until after the garbage collector has run the object finalizer. If the program needs the resource before the garbage collector has gotten around to finalizing the unreferenced object, the program is out of luck."
    http://www.javaworld.com/javaworld/jw-08-1996/jw-08-gc.html
    Generally without any tweaking the GC only runs when it has to, so your memory with be recycled then.
    You can call System.gc() but that doesn't cause garbage recycling, but rather tells the JVM that you would like to do it, and then it will do it sometime after that.

  • Remove background in JTree's node

    How to remove colored background in JTree's node?
    http://www.builder.cz/images/client-tree.gif - here is example how it looks like...

    from reading understand white would be best...
    You may have misunderstood.
    In the image you posted there seems to be a problem with a part that strongly reflects the background for example.
    The »ideal« color for efficient clipping depends on the object being photographed, even a green screen would be problematic with an object of a similar green.
    What is the file format you need anyway? psd with transparency or eps with Clipping Path or …?
    Like Silkrooster pointed out Actions and Image Processor, but also Scripts, can help with automising the task with Photoshop – but quite frankly I expect results so bad that each image would likely have to be checked and improved manually.

  • JTree multiple nodes selection problem !

    I can not make my JTree to be in multiple node selection mode.
    I have custom tree model and tree node class, the tree model class
    implements javax.swing.tree.TreeModel, and the tree node is an ordinary
    Java object.
    In this setting, my JTree is always in single selection mode.
    I have tried set the selection model after the JTree has initialized, and
    it didn't work.
    What I missed in TreeModel implementation ? Or should my tree node class
    also implements javax.swing.tree.TreeNode ?
    Don't tell me just call
    xxtree.getSelectionModel().setSelectionMode(javax.swing.tree.TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
    It didn't work.

    Just in case anyone wants to know, I did find the magic number of files, and what the problem is. I talked with tech suppot at Adobe, and they know the problem exists, but won't fix it. I did put in a request in the "Request a Feature" form. Read on:
    The magic number is 40 Canon 1Ds Mark III Raw files, and clicking on three or more keywords. The key to not having the numbers of keywords counted incorrectly in the filter pane is to click on the keywords as fast as you can before it starts to write to the metadata. If you click on each keyword one at a time, and wait about a second or more between selecting the keywords, then the counts in the filter panel for the number of keywords is not correct in relation to the number of files that you have chosen to apply keywords to. The cure for this is to click as many keywords as possible as fast as you can before the software starts incorporating the keywords into the metadata.
    I would suggest to Adobe, that a nice feature would be that one could click on as many keywords as one would want, to as many files one would want, and then have a button or icon that would enable one to then apply all the keywords at once, instead of applying them as you click them as it is now. I also would love it if Adobe fixed it now instead of waiting to fix it in the version of CS5. Someone on Adobe's support line told me that Adobe would rather wait to put this into the CS5 version than fix it now. I don't think that is right, but heck, I am only one guy who depends on this software to provide images keyworded to my clients in a timely manner. I would never run my business like this Adobe. If there is a problem, and there is, please fix it now, or give me some of my money back since your product has a design flaw that is having a negative impact in my ability to to my job and run my business.
    Thanks!
    Daniel Root
    Portland, OR

  • Jtree Select node and change leafs icon problem

    Hi All,
    i create a tree and implement a TreeSelectionListener:
    my mission is whenever i select a node i need to change the icon of this node (for now.later i will have to find if it have childrens).
    import java.awt.Color;
    import java.awt.Component;
    import java.util.Enumeration;
    import java.util.NoSuchElementException;
    import java.util.Vector;
    import javax.swing.ImageIcon;
    import javax.swing.JTree;
    import javax.swing.event.TreeExpansionEvent;
    import javax.swing.event.TreeExpansionListener;
    import javax.swing.event.TreeSelectionEvent;
    import javax.swing.event.TreeSelectionListener;
    import javax.swing.tree.DefaultMutableTreeNode;
    import javax.swing.tree.DefaultTreeCellRenderer;
    import javax.swing.tree.TreeModel;
    import javax.swing.tree.TreeNode;
    import javax.swing.tree.TreePath;
    public class TreeView{
         DefaultMutableTreeNode top;
         JTree tree ;
         Color frameColor;
         public static ImageIcon NoTSelIcon;
         public static ImageIcon SelIcon;
        public static String[] name= new String[8];
         public TreeView(Color BackColor) {
              // TODO Auto-generated constructor stub
            top =  new DefaultMutableTreeNode("Diagnostics");
            this.frameColor=BackColor;
             SelIcon = createImageIcon("../Resource/Images/Select.gif");
             if (SelIcon == null)
                 System.err.println("Tutorial icon missing; using default.");
             NoTSelIcon = createImageIcon("../Resource/Images/NotSelc.gif");
               if (NoTSelIcon == null)
                 System.err.println("Tutorial icon missing; using default.");
         public Component createTreeComponents(){
                //Create the nodes.
                 createNodes(top);
            //Create a tree that allows one selection at a time.
            tree = new JTree(top);
            //TREE LISTENERS
            //Treeselction listener
            Handler hObject = new Handler();
            tree.addTreeSelectionListener(hObject);
           //Tree expand/collapse listener
            HandlerExpansionListener hObjectExpan = new HandlerExpansionListener();
            tree.addTreeExpansionListener(hObjectExpan);
    //       tree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
            //set tree background
            tree.setBackground(frameColor);
             tree.setCellRenderer(new OverrideTreeCellRenderer(frameColor,SelIcon,NoTSelIcon));
            return tree;
          private void createNodes(DefaultMutableTreeNode top) {
                 DefaultMutableTreeNode category = null;
                 DefaultMutableTreeNode SubCategory = null;
                 DefaultMutableTreeNode SubCategoryBasee = null;
                 DefaultMutableTreeNode SubSubCategoryBasee = null;
                 category = new DefaultMutableTreeNode("Dfe");
                 top.add(category);
                 //Sub test visible
                 SubCategory = new DefaultMutableTreeNode("Test Visible");
                 category.add(SubCategory);
                 SubCategory.add(new DefaultMutableTreeNode("Son 1"));
                 SubCategory.add(new DefaultMutableTreeNode("Son 2"));
                 SubSubCategoryBasee = new DefaultMutableTreeNode("Test Base");
                 SubSubCategoryBasee.add(new DefaultMutableTreeNode("Grandson 1"));
                 SubSubCategoryBasee.add(new DefaultMutableTreeNode("Grandson 2"));
                 SubCategory.add(SubSubCategoryBasee);
          class Handler implements TreeSelectionListener {
                   public void valueChanged(TreeSelectionEvent arg0) {
                        // TODO Auto-generated method stub
                        System.out.println("treeSelect event ");
                        TreePath trph;
                        trph=arg0.getNewLeadSelectionPath();
                        int count=trph.getPathCount();
                        DefaultMutableTreeNode Selnode = (DefaultMutableTreeNode)tree.getLastSelectedPathComponent();
                        String Name = (String)Selnode.getUserObject();
                        setSelected(Selnode,true);
                        int number_ofnodes=getNodeCountBelow((TreeModel)tree.getModel() , Selnode, false);
                        System.out.println("The Number of nodes under "+Name+"="+number_ofnodes);
                        tree.setCellRenderer(new IconRenderer(SelIcon,NoTSelIcon,frameColor));
          class HandlerExpansionListener implements TreeExpansionListener {
                   public void valueChanged(TreeSelectionEvent arg0) {
                        // TODO Auto-generated method stub
                        DefaultMutableTreeNode node = (DefaultMutableTreeNode)  tree.getLastSelectedPathComponent();
                        if (node == null) return;
                      }     // The inner class
                   public void treeCollapsed(TreeExpansionEvent arg0) {
                        // TODO Auto-generated method stub
                        System.out.println("treeCollapsed event ");
                   public void treeExpanded(TreeExpansionEvent arg0) {
                        // TODO Auto-generated method stub
                        System.out.println("treeExpanded event ");
          /** Returns an ImageIcon, or null if the path was invalid. */
             protected static ImageIcon createImageIcon(String path) {
                  //ImageIcon imcon= new ImageIcon(path);
                  //return imcon;
                 java.net.URL imgURL = TreeView.class.getResource(path);
                 if (imgURL != null) {
                     return new ImageIcon(imgURL);
                 } else {
                     System.err.println("Couldn't find file: " + path);
                     return null;
             DefaultMutableTreeNode newnode;
             public void setSelected(DefaultMutableTreeNode Selnode ,boolean isSelected)
                    Enumeration Enchilds=Selnode.children();//ENUMRATE ALL CHILDS FOR THIS NODE
                 if (Enchilds != null)
                      while (Enchilds.hasMoreElements())
                           newnode=(DefaultMutableTreeNode)Enchilds.nextElement();
                           String NameSel = (String)newnode.getUserObject();
                           setSelected(newnode,isSelected);
             //GETTING THE TREE DEPTH
             public int getNodeCountBelow(TreeModel model, Object node, boolean includeInitialNode)
                 int n = includeInitialNode ? 1 : 0;
                 for (int i = 0; i < model.getChildCount(node); i ++)
                     n += getNodeCountBelow(model, model.getChild(node, i), true);
                 return n;
    import java.awt.Color;
    import java.awt.Component;
    import java.util.Enumeration;
    import java.util.NoSuchElementException;
    import javax.swing.Icon;
    import javax.swing.JTree;
    import javax.swing.tree.DefaultMutableTreeNode;
    import javax.swing.tree.DefaultTreeCellRenderer;
    public class IconRenderer extends DefaultTreeCellRenderer {
         private static final long serialVersionUID = 1L;
         Icon SelectedIcon;
         Icon NotSelectedIcon;
         Color BackgroundColor;
         boolean Selected=false;
         boolean Leaf=false;
         boolean IsItaChild=false;
         DefaultMutableTreeNode SelctedNode=null;
        public IconRenderer(Icon SelIcon,Icon NoTSelIcon,Color Bacground) {
             SelectedIcon = SelIcon;
             NotSelectedIcon = NoTSelIcon;
             BackgroundColor=Bacground;
             setBackgroundNonSelectionColor(BackgroundColor);
        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);
             Selected=sel;
             Leaf=leaf;
             DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
             String s2 = (String)node.getUserObject();
       return this;
    }my problem is :
    when i select a node the the method "getTreeCellRendererComponent"
    start to run on the entire tree from buttom to top and than from top to buttom.
    for me it waste of time because if has say 100 nodes it wont botthers me.
    but i have 20000 nodes and more its take a time.
    and for all this nodes i have to make compares.
    is there a way to force the DefaultTreeCellRenderer to not run the entire tree???
    Thanks

    You need to make sure that your TreeModel interprets your group nodes to be non-leaf nodes (one of the methods in the TreeModel interface is called isLeaf). If you are using a DefaultTreeModel with DefaultMutableTreeNode objects, you can use the askAllowsChildren property of DefaultTreeModel and the allowsChildren property of DefaultMutableTreeNode to control this. See the API for more details:
    http://java.sun.com/j2se/1.4.2/docs/api/javax/swing/tree/DefaultTreeModel.html
    http://java.sun.com/j2se/1.4.2/docs/api/javax/swing/tree/DefaultMutableTreeNode.html

  • Updating JTree Using a Custom TreeModel

    Hello,
    I have created a custom TreeModel that implements the TreeModel interface. The underlying data objects are stored in an existing tree structure similiar to a file/directory filesystem. When I add a new "file" object to the data model, I want to see it in the tree immediately. To make a long question short: what are the necessary steps to communicate with the JTree? Any info or references would be much appreciated.
    Thank You

    Thank you for your reply.
    Are you adding nodes or just expanding the JTree?Adding nodes (I also want to delete nodes)
    I don't know how to do this by just implementing
    TreeModel. This is using DefaultTreeModel.Yeah, I really don't want to use DefaultTreeModel because I would have to wrap my data objects as TreeNodes. Since my data objects are already in a tree structure, implementing TreeModel is much cleaner.
    It looks like I have to implement fireTreeNodesInserted() in my TreeModel, but I guess what I need to understand is how to register the JTree as a listener to my custom TreeModel. JTree doesn't directly implement TreeModelListener. I read somewhere that JTree automatically registers itself with the TreeModel, but that is not what I am observing.
    So..., I am still in need of more info.

  • JTree adding nodes

    Hello all,
    I have two questions concerning Trees,
    1. I have created the Tree by the JTree(Vector) method, initially the vector does have some elements but i have to add some more later, so when my vector gets updated how can I add the same element to the tree in the form of a node?
    2. The Tree being created like this, has automatically generated names for the nodes (i guess it shows the memory address) but i want to change the name of all of my nodes, what is the method for renaming nodes?

    There are two pieces of Trees that you have not yet found. The first is the TreeModel, which is accessible through myTree.getModel(). You can use this model to create the data structure; the JTree object is simply a view of that model.
    The second piece is the TreeCellRenderer, accessible through myTree.getCellRenderer(). This renderer is used to draw the nodes of the tree and, by default, one is used that renders the Strings returned by the toString() method of the objects in the model. To display different strings, you can either (1) replace the renderer or (2) override the toString() method on the objects in your model. The first is recommended if the strings vary radically from the desired result of toString() or if toString() is being used for something else; the second is recommended for simplistic models or for situations in which the display properly reflects the nature of the object.
    Replacing the renderer also allows you to use any JComponent for rendering you wish. This can give you the ability to present gradient backgrouns, dynamically loaded icons, etc.
    Many objects in Swing use this format in which there are three portions of an object: the view (which is the standard object, like an instance of JTree, JList, or JTable), the model (which contains the actual data structure), and the renderer (which acts like a rubber stamp to draw the objects without causing more than one object to be instantiated to render thousand-element lists).

  • JTree - Create nodes and expand

    Hi there,
    I have made a file-tree from the swing jtree, where My Computer is the root, then C:/ etc, Program Files, etc...
    The problem I'm having is that I'm trying to open up a node if a link has been clicked. For example.. if A shortcut to C:/Program Files/Pictures/pic.jpg was clicked, then it should go the C:/ node, create it's children, and expand it, go to Program Files node, create it's children and expand it, etc until pic.jpg is visible.
    TreePath x = new TreePath(ta);
    TreePath y = x.pathByAddingChild(myComputer);
    TreePath z = y.pathByAddingChild(programFiles);
    tree.expandPath(y);
    The above is the general idea of what I'm trying... I can't see why this doesn't work. (ta is empty root folder, then myComputer and programFiles are other treenodes).
    Any ideas?
    Thanks.
    David

    Create your TreeModel using the FileSystem as the underlying data store, as shown in this article:
    http://java.sun.com/products/jfc/tsc/articles/jtree/
    The use JTree#setAnchorSelectionPath when the user clicks on a file to select that item in the tree. Also look at JTree#scrollPathToVisible if your JTree is in a scroll pane.

  • How to change JTree's node icon manually?

    Hi, I'm currently making messenger application using awt and swing. I've searched in google and here(got this), but till now I haven't got solution.
    I want to change user's status icon in the buddy list if the user's status is changed(such like offline and online).
    But for now I want to try to change the icon directly by pressing a button first before thinking about listener for the status.
    I have this tree
         CustomCellRenderer rosterTreeRenderer = new CustomCellRenderer();
            DefaultMutableTreeNode rosterRoot = new DefaultMutableTreeNode("root");
            DefaultMutableTreeNode rosterGroup = null;
             rosterGroup = new DefaultMutableTreeNode("group 1");
             rosterRoot.add(rosterGroup);
             rosterGroup.add(new DefaultMutableTreeNode("abc"));
             rosterGroup.add(new DefaultMutableTreeNode("dce"));
             rosterGroup = new DefaultMutableTreeNode("group 2");
             rosterRoot.add(rosterGroup);
             rosterGroup.add(new DefaultMutableTreeNode("zzz"));
             rosterGroup.add(new DefaultMutableTreeNode("xxx"));
             rosterGroup.add(new DefaultMutableTreeNode("yyy"));
                rosterTree.setCellRenderer(rosterTreeRenderer);This is the cell renderer
    public class CustomCellRenderer extends DefaultTreeCellRenderer
         private static final long serialVersionUID = 1L;
         public CustomCellRenderer(){
            public Component getTreeCellRendererComponent( JTree tree, Object value,
                    boolean isSelected, boolean expanded, boolean leaf, int row,
                    boolean hasFocus )
              DefaultMutableTreeNode node = (DefaultMutableTreeNode)value;
              String     labelText = (String)node.getUserObject();
              if (isSelected)
                   System.out.println("selected");
                   this.setIcon(UIManager.getIcon("Tree.openIcon"));
                   //((DefaultTreeModel) tree.getModel()).nodeChanged(node);
            else if (leaf) {
                this.setIcon(UIManager.getIcon("Tree.leafIcon"));
              } else if (expanded) {
                   this.setIcon(null);
              } else {
                   this.setIcon(null);
              setText(labelText);
              return this;
        public Color getBackgroundNonSelectionColor() {
            return(null);
        public Color getBackground() {
            return(null);
    }Whenever I click the user, the user's icon change, the first phase of my testing is working.
    But after that I'm confused, how can I change the icon when I click a button at the roster frame. How to invoke and send parameter to change icon of specified user? I already read DefaultTreeCellRenderer javadoc but still haven't found clue to what I wanted, most of the methods noted with "Overridden for performance reasons".
    I've already searched for several days for this problem.. Hope someone can help me..
    Thanks

    Sorry I don't know how to delete my question from other forum. I also don't know about crossposting rule(I don't go into javaranch).
    I'm learning java by google and I'm really confused now, everyone I asked in real life doesn't know the solution. I'm doing a thesis making chat messenger, my lecturer also doesn't know how to solve my problem.
    Sorry I really don't know about the crosspoting rule. I only read the rule from each forum.
    Can someone help me please? :(

  • Refreshing JTree with a customized TreeModel

    Hello,
    I'm newer to Swing, and I'm seeking for help for a JTree problem.
    I hoped to display an XML document with JTree. So I customized a TreeModel and TreeNode to handle the XML data.
    I used DOM to handle XML, and define TreeNode with the following class:
    class DOMtoTreeNode {
    org.w3c.dom.Node domNode;
    public DOMtoTreeNode(org.w3c.dom.Node myNode){
    this.domNode = myNOde; }
    public String toString() {
    //the displaying code
    //and other necessary code to handle children of domNode
    Then I defined an implementation of the TreeModel Interface.
    public class DomTreeModel implements javax.swing.tree.TreeModel
    Document document;
    public DomTreeModel(Document aDomDoc){   
         this.document = aDomDoc;
    // Basic TreeModel operations
    I didn't define any personal TreeModelListener for this TreeModel
    and then I created a JTree object to display the XML tree
    treeModel = new DomTreeModel(someDOMDocument);
    treeInputParameter = new JTree( treeModel );
    and I defined JtreeListener.
    What I hoped to do is to make modification for the XML document in the JTree.
    I added the editing functions in the "valueChanged" function. I added a new DOM node as a child of an existing element node by directly append the child in the DOM node. The code is like the follows:
    DOMToTreeNode treeNodeSelected =(DOMToTreeNode)
    treeInputParameter.getLastSelectedPathComponent();
    org.w3c.dom.Node domNode = treeNodeSelected.getNode();
    //get the dom node from Jtree Node here
    domNode.appendChild(someChildDomNode);
    Up to now, it seems work fine. The TreeModel updates the DOM Document, and the modification being shown in JTree.
    But when I tried to replace an existing node with a new node, something went wrong.
    domNode.replace(newChild, oldChild);
    I debugged the code, and found the underlying DOM Document in the TreeModel had been successfully changed, but the TreeModel didn't update the display in JTree.
    I'm afraid this is quite a naive question, but would someone be kindly help me deal with this? It seems that the reason is that some code is missing to let the TreeModel refresh the frontend JTree display. But I realy don't know how to tackle this.
    Thanks!
    Haoxiang Xia

    Thank you for your reply.
    Are you adding nodes or just expanding the JTree?Adding nodes (I also want to delete nodes)
    I don't know how to do this by just implementing
    TreeModel. This is using DefaultTreeModel.Yeah, I really don't want to use DefaultTreeModel because I would have to wrap my data objects as TreeNodes. Since my data objects are already in a tree structure, implementing TreeModel is much cleaner.
    It looks like I have to implement fireTreeNodesInserted() in my TreeModel, but I guess what I need to understand is how to register the JTree as a listener to my custom TreeModel. JTree doesn't directly implement TreeModelListener. I read somewhere that JTree automatically registers itself with the TreeModel, but that is not what I am observing.
    So..., I am still in need of more info.

  • (JTree)Full node caption is not visible

    Hello everyone,
    I am a novice swing developer.
    I have generated JTree by implementing TreeModel interface.
    I show node caption by overriding toString() metod of node object.
    Now on valueForPathChanged event i make changes in child node so node caption changes accordingly.
    But full node captions are not displayes instaead it shows partial name followed by ...
    Kindly suggest appropriate solution.

    This sounds backwards to me! I would expect you to fire the 'valueForPathChanged' event when you update the value associated with a node.

  • Jtree custom nodes

    Hi there,
    the "How to Use Trees" tutorial shows how to create simple JTrees where each node is a String:
    http://java.sun.com/docs/books/tutorial/uiswing/components/tree.html
    I need to have tree structure where each node is like a form entry.
    For example some like this:
    + name: [ ........... ]
    + surname: [ ........... ]
    + child
    ---------+ name: [ ........... ]
    ---------+ surname: [ ........... ]
    and so on...
    The best way that I can think of to do that is to make each node be a JPanel and add to it a JLabel and a JTextField. If this is really the best way to do that then my JTree needs to have something different than DefaultMutableTreeNode as nodes because they can only be used to display Strings.
    So provided there is no better way to do what I want to do, the question is, how do I put a JPanel in a JTree node?

    I think the better way is to use a UserObject giving a summary String in its toString method for standard node display, and to display an extra JDialog for editing all the details of the UserObject if the user chooses to edit the node. Imho, displaying complex nodes directly in the tree tends to confuse the user.

  • Refresh JTree keep node x-y position

    Hi,
    I have a JTree which is the folders of the file system. Over time, new folders added/deleted before/after a selected node, so I need to refresh it. How to keep the selected node at the same x-y location of the view?
    I can keep the selected node in the view (visible), but the x-y position may change.
    Any information would be appreciated. Thanks in advance.

    Without seeing any code, tha best I can offer is
    -- before refreshing, store the visible rectangle and the location of the selected node
    -- after refreshing, obtain the location of the selected node and compute the offset
    -- compute the new desired visible rectangle and scrollRectToVisible
    To get better help sooner, post a [_SSCCE_|http://mindprod.com/jgloss/sscce.html] that clearly demonstrates your problem.
    Use code tags to post codes -- [code]CODE[/code] will display asCODEOr click the CODE button and paste your code between the {code} tags that appear.
    db

  • Jtree; searching node by inserting path name

    Hello,
    I have a jtree which allows me to explore my harddisk.
    The thing I want is finding a directory by inserting a path name ( with a JTextfield).
    I am already able to reveice the inserted path.
    But how do I let the JTree go to that inserted path name?
    For more information, just ask.
    Grtz

    well, if you have the node and are using DefaultTreeModel, you can call: getPathToRoot(TreeNode)
    Not sure how to find the node from the value except to just loop thru the entire tree... or maintain a separate table of value/node objects.

  • JTree same nodes

    Hy,
    I have a problem with the treeselectionlistener.
    I want to show data from a database using a JTree but the problem is that some nodes have the same name. So the methode
    public void valueChanged(TreeSelectionEvent event){
                                  TreePath path = tree.getSelectionPath();
         String test = path.getLastPathComponent().toString();
    gives a lot of times the same value.
    Is there a possibility to identify the selected node like an array that shows the number of the selected node.
    Like [2,5,1] this would than mean node 2 of first row node 5 of second row and first node of 3th row?
    Thx Mette

    you could extend DefaultTreeNode and add a variable which will correspond to Key Field in your table like:
    public class MyCustomTreeNode extends DefaultTreeNode {
    private int nodeId;
    //code if needed
    or you could play with TreePath object... more on:
    http://java.sun.com/j2se/1.5.0/docs/api/javax/swing/tree/TreePath.html

Maybe you are looking for

  • Windows 8 Fresh Install on Yoga 13

    I have spent several hours now reading on how to do a fresh Windows 8 install on the Yoga  13.  I have the newer Yoga 13 with 8GB RAM and 256GB SSD. I have a 32GB USB thumb drive and access to my TechNet media.  I ensured the thumb drive was formatte

  • Content conversion using PI MDM adapter in PI 7.1

    Hello All, I am using the PI MDM adapter in PI 7.1. I have a scenario ECC - PI - MDM .   ECC will send an IDoc to PI and we need to send a flat file to MDM. So is it possible to convert the IDoc XML in PI to flat file using PI MDM adapter , and if ye

  • How do record my band practice on my Macbook?

    I have a real garage band, and would like to make simple recordings of our practices so I can distribute them to the players on CD. I don't want to mess with different channels, and mikes. I just want to set the computer up in the room and record the

  • In Query mode, date items does not accepts more than 10 characters..Why?

    Dear All, In my form, While querying my date items, it does not accepts more than 10 Characters. Could it be changeable. Actually i want to search like greater than specified date( >01/01/2007 ). But i can specify like >01/01/07. After tabbing out fr

  • How to install downloaded ringtone from i-tunes on iphone 4

    Can anhyone help me??? I downloaded a ringtone from i-tunes, but I cannot get it installed as a ringtone on my iphone 4....