Get a certain node of a JTree

Hi to all!
I' m using JTree combined with DefaultMutableTreeNode and DefaultTreeModel.
My problem is that I have the path of a certain node and I just want to get a certain node of this path in order to edit (or better to update) its "userObject".
Maybe it's a silly question but I'm new to JTree and I feel a little lost with all these methods provided.
Thank you in advance.

For starters: excellent photography, and great lighting knowledge and skills. With great photography and lighting, you really don't need to do major alterations other than some minor improvements. i would say instead of looking for lightroom to make it better, instead improve the quality of your photos. lightroom is a tool, not a result to good photos. 
with that said, reference these links:
http://thelightroomlab.com/2009/10/camera-raw-profiles-in-adobe-photoshop-lightroom/
http://layersmagazine.com/photographic-workflow-from-lightroom-to-photoshop.html
http://tv.adobe.com/watch/getting-started-with-adobe-photoshop-lightroom-4/lightroom-4-cre ate-stunning-images/
janelle

Similar Messages

  • How could i get the selected node in the JTree

    getLastSelectedPathComponent() �returns the parent node of currenr selected, so how could I get the selected node itself in the JTree
    I will appretiate for any help!

    i think you can get by....
    TreePath treePath = tree.getSelectionPath();
    DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode) treePath.getLastPathComponent();

  • Selectively editing nodes in a JTree

    I need to make certain nodes in a JTree editable, without making every node in the tree editable. How can I accomplish this?

    Is there some kind of method in a JTree or a DefaultMutableTreeNode that I can call to select the node's text and be able to change it?Hmm. And you did read the API for JTree looking for such methods before you posted here, didn't you?
    So tell us which methods you found to be likely candidates.
    db

  • How to get total number of nodes in a JTree?

    Hi,
    I am trying to get total number of nodes in a JTree, and cannot find a way to do it.
    The current getRowCount() method returns the number of rows that are currently being displayed.
    Is there a way to do this or I am missing something?
    thanks,

    How many nodes does this tree have?
    import java.awt.EventQueue;
    import javax.swing.*;
    import javax.swing.event.TreeModelListener;
    import javax.swing.tree.*;
    public class BigTree {
        public static void main(String[] args) {
            EventQueue.invokeLater(new Runnable() {
                public void run() {
                    TreeModel model = new TreeModel() {
                        private String node = "Node!";
                        @Override
                        public void valueForPathChanged(TreePath path,
                                Object newValue) {
                            // not mutable
                        @Override
                        public void removeTreeModelListener(TreeModelListener l) {
                            // not mutable
                        @Override
                        public boolean isLeaf(Object node) {
                            return false;
                        @Override
                        public Object getRoot() {
                            return node;
                        @Override
                        public int getIndexOfChild(Object parent, Object child) {
                            return child == node ? 0 : -1;
                        @Override
                        public int getChildCount(Object parent) {
                            return 1;
                        @Override
                        public Object getChild(Object parent, int index) {
                            return node;
                        @Override
                        public void addTreeModelListener(TreeModelListener l) {
                            // not mutable
                    JFrame frame = new JFrame("Test");
                    frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
                    frame.getContentPane().add(new JScrollPane(new JTree(model)));
                    frame.pack();
                    frame.setLocationRelativeTo(null);
                    frame.setVisible(true);
    }But for bounded tree model using DefaultMutableTreeNode look at bread/depth/preorder enumeration methods to walk the entire tree. Or look at the source code for those and adapt them to work with the TreeModel interface.

  • How do I get a dotted line to connect nodes in a JTree?

    I am trying to recreate a Windows Explorer application, does anyone know how they get the dotted lines to connect the nodes in the JTree????

    JTree uses a specific line style to represent the edges between nodes. The default is no edges, but we can set JTree�s lineStyle client property so that each parent node appears connected to each of its child nodes by an angled line:
    myJTree.putClientProperty("JTree.lineStyle", "Angled");
    We can also set this property such that each tree cell is separated by a horizontal line:
    myJTree.putClientProperty("JTree.lineStyle", "Horizontal");
    To disable the line style:
    myJTree.putClientProperty("JTree.lineStyle", "None");
    As with any Swing component, we can also change the UI resource defaults used for all instances of the JTree class. For instance, to change the color of the lines used for rendering the edges between nodes as described above, we can modify the entry in the UI defaults table for this resource as follows:
    UIManager.put("Tree.hash", new ColorUIResource(Color.lightGray))
    Hope this serves your purpose.
    Regards,
    Sachin Shanbhag

  • How can I get a count of ALL nodes in a JTree?

    Not sure if I am missing something here or what. Is there an easy way to determine the total number of nodes in a JTree? I thought there would be a method to return this, but I'm not seeing it in JTree or DefaultTreeModel. Do I have to start at the root and recursively get child counts? Yuck!
    Jamie

    You are absolutely right! Create a recursive method and count all your children from the root.
    Denis Krukovsky
    http://dotuseful.sourceforge.net/

  • Getting TreePath for all nodes in a JTree

    Hi everybody
    I want to get TreePath for all the nodes in a JTree
    Can anybody help me?

    Hi,
    i tried to used your code.
    there is a problem, it is not taking the entire paths.
    so if you have some children,it takes the paths only for the fathers.
    so i correct it to the following way(it will take the entire paths):
    public void getPathForAllNodes(TreePath path)
                  Object node = path.getLastPathComponent();
                  pathArrayList.add(path);
                  TreeModel model = tree.getModel();
                  if(model.isLeaf(node))
                  return;
                  int num = model.getChildCount(node);
                  for(int i = 0; i < num; i++)
                       //pathArrayList.add(path);
                       getPathForAllNodes(path.pathByAddingChild(model.getChild(node, i)));
             }thanks for your code

  • How do I get a list of nodes of a JTree?

    I'm getting confusing while reading APIs on JTree and DefaultMutableTreeNode.
    My question is as simple as this: how do I get a list (or array) of nodes on the specified level of a JTree?
    Please help! Thanks!

    Use the children method on DefaultMutableTreeNode. It'll return an Enumeration of all the children for a given node. - MOD

  • How to get a node  in a Jtree on which right mouse button is clicked

    I am dealing with a situation in which whenever tree component is clicked by right mouse button I am needed to get the tree node on which right mouse button was clicked.

    MouseEvent e = ...
    TreePath path = tree.getPathForLocation(e.getX(), e.getY());
    Object nodeClickedOn = path.getLastPathComponent();Or something along those lines.

  • Hiding / Filtering nodes in a JTree

    I'm not exactly sure how to temporarily hide or filter nodes from a JTree. My scenario is described below.
    I have a radio button group. If the first radio button is selected, all nodes are displayed. If the second button is selected, certain nodes are hidden.
    Here is my attempt to filter nodes. I get the following excpetion when I try to filter nodes:
    java.lang.NullPointerException: Null child not allowed
    I assume this is coming from the getChild() method. I don't know what else to return besides null if I'm trying to filter the node out.
    Can anyone provide some help or insight?
    Thanks
    import javax.swing.tree.DefaultTreeModel;
    import javax.swing.tree.DefaultMutableTreeNode;
    public class MyTreeModel extends DefaultTreeModel
        * Constructor.
        * @param rootNode The root node.
       public MyTreeModel( DefaultMutableTreeNode rootNode )
          super( rootNode );
        * Gets the child node.
        * @param parent The parent node.
        * @param index The index this child node resides in.
        * @return The child node.
       public Object getChild( Object parent, int index )
          Object child = super.getChild( parent, index );
          if ( RadioBtn.hideNodes() )
             DefaultMutableTreeNode dmtn = ( DefaultMutableTreeNode ) child;
             MyNode eNode = ( MyNode ) dmtn.getUserObject();
             if ( !eNode.hasPermission() )
                child = null;    // "hide" the node
          return child;
        * Gets the index of a child.
        * @param parent The parent node.
        * @param child The child node.
        * @return The index of the child node.
        public int getIndexOfChild( Object parent, Object child )
           int index = super.getIndexOfChild( parent, child );
           if ( RadioBtn.hideNodes() )
              DefaultMutableTreeNode dmtn = ( DefaultMutableTreeNode ) parent;
              MyNode eNode = ( MyNode ) dmtn.getUserObject();
              if ( !eNode.hasPermission() )
                 index = -1;
           return index;
        * Returns the number of children attached to the parent node.
        * @param parent The parent node.
        * @return The number of children of the parent node.
       public int getChildCount( Object parent )
          int numChildren = super.getChildCount( parent );
          if ( RadioBtn.hideNodes() )
             int counter = 0;
             DefaultMutableTreeNode dmtn = ( DefaultMutableTreeNode ) parent;
             // Loop through children and keep a count of all children nodes that should stay
             for ( int x = 0; x < numChildren; x++ )
                DefaultMutableTreeNode childDmtn = ( DefaultMutableTreeNode ) dmtn.getChildAt( x );
                MyNode eNode = ( MyNode ) childDmtn.getUserObject();
                if ( eNode.hasPermission() )
                   counter++;
             numChildren = counter;
          System.out.println( "Number of children in " + ( DefaultMutableTreeNode ) parent + ": " + numChildren );
          return numChildren;
        * Used from radio buttons to toggle hidden folders on and off.
       public void triggerMe()
          reload();

    Here it is optimized, for anyone who may need the code down the road.
       public Object getChild( Object parent, int index )
          Object child = super.getChild( parent, index );
          if ( RadioBtn.isHidden() ) // If we should remove the 'special' nodes
             DefaultMutableTreeNode dParent = ( DefaultMutableTreeNode ) parent;
             int count = 0;
             // Loop through children
             for ( int x = 0; x < dParent.getChildCount(); x++ )
                DefaultMutableTreeNode dChild = ( DefaultMutableTreeNode ) dParent.getChildAt( x );
                MyNode eNode = ( MyNode ) dChild.getUserObject();
                if ( eNode.hasPermission() )
                   // If it is the "xth" visible node, break the loop and set this object as the Child node
                   if ( count == index )
                      child = dChild;
                      break;
                   count++;
          return child;
       }

  • Dynamically changing the color of nodes in a JTree

    I have created a JTree and want to dynamically change the color of some of the TreeNodes as my program runs. The JTree is displayed in a JPanel. There is an algorithm built into which identifies the nodes whose color I need to change. No user actions is performed (everythign is internal to the program).
    It seems that in the TreeCellRender only kicks in when the tree is first displayed. How do I get it to re-render the tree when the TreeModel changes? It seems that the Listeners are only looking for external user interactions.
    Any help would be greatly appreciated.
    Thanks!

    I think I was a bit too vague in my question. Let me try again...
    I have changed an attribute in a node in a JTree. This attribute is changed after the tree was initially rendered, but while the program is still running. I want to tell the TreeCellRenderer to look again at this node since that attribute that was changed will effect how the node should be renderered. I tried using the nodeChanged() method, but it did not work (the colot of the node did not change). Any advise how I can do this?
    Thanks!

  • Events of Nodes in a JTree

    Okay, perhaps I am sidetracked today by all the sad craziness occuring in New York and DC, or perhaps I just don't have a grasp on JTrees yet...but...
    I have implemented a TreeCellRender to create panels with buttons and other information to be the nodes of a JTree I created. Everything shows up beautifully, however, I want the buttons on this panel to depress and perfom actions (work like normal) when the user clicks/selects such a button in the tree structure. I can't figure out how to properly set up event handlers to get from the tree to the tree node to the "bean" I'm using as a node. If anyone has any helpful hints, I'd appreciate it!
    Thanks in advance!

    add actionlistener to the JTree, and then get the object by getLastPathComponent, and compare it if its the button and do the action.

  • Highlighting nodes in a JTree

    Hi,
    I'd like to know how I can produce the efect of highlighting nodes in a JTree when the mouse moves over the JTree.
    Thanks

    You say to get the mouseevent coordinates with a mouse
    listener, but which component should be the caller of
    the methos addMouseListener?
    If I choose the jtree, I can't get the 'mouseevent
    coordinates' each time the mouse moves over a node,
    because the methods mouseEntered and mouseExited are
    invoked just once (when the mouse enter inside the
    jtree's area (mouseEntered), and when the mouse gets
    out the jtree's area(mouseExited)), so I can't change
    the boolean field to true for nodes which have the
    mouse over.just use mouseMoved of the MouseMotionListener.
    however, i have my doubts that you will have a lot of fun with the suggested method (correct though it is).
    at least make sure you only call the repaint method if the mouse moved into a new node. you might want to try the the nodeChanged method, that way you don't repaint the whole tree every time.
    thomas

  • How can i change the particular node color in Jtree?

    I have constructed the tree.i dont know how to set the color for the particular node then how can i change the particular node icon depends on some conditions like if we will give the input whether it is available in jtree that node icon only changed.Anyone please help me as soon as possible.

    hi,
    i saw that tutorial.from that book i dont get the particular node cell renderer.i got a cell renderer for tree only.i attached my code in this mail.pls see and help me if u will do
    mport pack.Prop;
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Component;
    import java.awt.Container;
    import java.awt.Font;
    import java.io.BufferedReader;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.util.Properties;
    import java.util.Set;
    import java.util.StringTokenizer;
    import java.util.Vector;
    import javax.swing.Icon;
    import javax.swing.ImageIcon;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JScrollPane;
    import javax.swing.JTree;
    import javax.swing.UIManager;
    import javax.swing.text.Position;
    import javax.swing.tree.DefaultMutableTreeNode;
    import javax.swing.tree.DefaultTreeCellRenderer;
    import javax.swing.tree.DefaultTreeModel;
    import javax.swing.tree.MutableTreeNode;
    import javax.swing.tree.TreeCellRenderer;
    import javax.swing.tree.TreePath;
    public class ReadProperty3 extends JFrame{
    String str,key;
    static JTree tree;
    static Vector v;
    StringTokenizer st;
    static DefaultMutableTreeNode root;
    DefaultMutableTreeNode t;     
    public Object[] o;
    public static void main(String[] args) throws IOException {
    ReadProperty3 r = new ReadProperty3();
    Prop p=new Prop();
    JFrame f=new JFrame();
    p.show();
    Object[] o=v.toArray();
    int startRow = 0;
    String prefix =p.s;
    TreePath path = tree.getNextMatch(prefix, startRow, Position.Bias.Forward);
    //if(prefix.equals(root.getChildAt(0).toString()))
    if(prefix.equals("2000"))
         System.out.println("Node 2000 found");
         else if(prefix.equals("3000"))
              System.out.println("Node 3000 found");
         else if(prefix.equals("4000"))
              System.out.println("Node 4000 found");
         else
              System.out.println("Node not found");
         for(int i=0;i<v.size();i++)
              //((DefaultTreeModel)tree.getModel()).reload();
              DefaultTreeCellRenderer ren=(DefaultTreeCellRenderer)tree.getCellRenderer();
              Icon openIcon = new ImageIcon("C:/apache-tomcat-5.5.12/webapps/jsp-examples/images/execute.gif");
              Icon closedIcon = new ImageIcon("C:/apache-tomcat-5.5.12/webapps/jsp-examples/images/execute.gif");
              Icon leafIcon = new ImageIcon("C:/apache-tomcat-5.5.12/webapps/jsp-examples/images/read.gif");
              if(o[0].equals(p.s))
                   ren.setBackgroundSelectionColor(Color.MAGENTA);
                   ren.setBackgroundNonSelectionColor(Color.YELLOW);
                   //ren.setTextSelectionColor(Color.YELLOW);
                   //ren.setTextNonSelectionColor(Color.BLUE);
                   ren.setClosedIcon(closedIcon);
                   ren.setFont(new Font("Impact",Font.ITALIC,14));
              else if(o[1].equals(p.s))
                   ren.setLeafIcon(leafIcon);
                   ren.setFont(new Font("Impact",Font.ITALIC,10));
                   UIManager.put("Tree.leafIcon", leafIcon);
              else if(o[2].equals(p.s))
                   ren.setOpenIcon(openIcon);
                   ren.setFont(new Font("Dialog",Font.BOLD,9));
    public ReadProperty3(){
         super("JTree With Properties");
         try{
    int c = 0;
    while(c == 0){
    c = 1;
    BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
    System.out.print("Enter file name which has properties extension :");
    str = bf.readLine();
    File f = new File(str + ".properties");
    if(f.exists()){
    Properties pro = new Properties();
    FileInputStream in = new FileInputStream(f);
    pro.load(in);
    System.out.println("Key: " + pro.keySet());
    System.out.print("Enter Key : ");
    key = bf.readLine();
    String p = pro.getProperty(key);
    st = new StringTokenizer(p,"=,");
    root=new DefaultMutableTreeNode(key);
    v=new Vector();
    while(st.hasMoreTokens())
         String val=st.nextToken();
         v.add(val);
         o=v.toArray();
         System.out.println(val);
         t=new DefaultMutableTreeNode(val);
         root.add(t);
         tree=new JTree(root);
         tree.setEditable(true);
         JScrollPane jp=new JScrollPane(tree);
         // tree.setCellRenderer(new CellRenderer());
         Container content=getContentPane();
         content.add(jp,BorderLayout.CENTER);
    setSize(250,275);
    setVisible(true);
    addWindowListener(new ExitListener());
    else{
    c = 0;
    System.out.println("File not found!");
    catch(IOException e){
    System.out.println(e.getMessage());
    }

  • Changing Certain Node Icons

    I can't seem to figure out how to change certain node icons in a JTree due to a 3 letter string. For example 2 nodes one saying "Intro" the other say "Edit - SEC" - the one with SEC has a different icon to "Intro"
    MyRenderer class, here the code which is used to check the string of the node......
    if(leaf && isSecuredFile(value)) {
    setLeafIcon(leafSecuredIcon);
    setToolTipText("This file is Secured Access Only");
    else {
    setToolTipText(null);
    return this;
    protected boolean isSecuredFile(Object value) {
    DefaultMutableTreeNode node = (DefaultMutableTreeNode)value;
    NodeRecord nodeInfo = (NodeRecord)(node.getUserObject());
    String nodeTitle = nodeInfo.NodeRecord;
    if(nodeTitle.indexOf("SEC") >= 0) {
    return true;
    return false;
    }// MyRenderer class
    I tried the above piece of code, and it compiles with no errors but when I try to run the applet it comes up not initialised with the following....
    java.lang.NoClassDefFoundError: MyRenderer
    at firstPanel.<init>(firstPanel.java:99)
    at JNavigator.jInit(JNavigator.java:55)
    at JNavigator.init(JNavigator.java:40)
    at sun.applet.AppletPanel.run(AppletPanel.java:344)
    at java.lang.Thread.run(Thread.java:484)
    However if I take out this code it works fine but I need to be able to assign different icons depending on the node title string. Therefore I need help.

    here's the whole class, if thats any help...
    public class MyRenderer extends DefaultTreeCellRenderer {
    ImageIcon leafIcon;
    ImageIcon leafSecuredIcon;
    public MyRenderer() {
    leafIcon = new ImageIcon("Leaf.gif");
    leafSecuredIcon = new ImageIcon("LeafSecured.gif");
    public Component getTreeCellRendererComponent(JTree tree, Object val, boolean sel, boolean expand, boolean leaf, int row, boolean hasFocus) {
    super.getTreeCellRendererComponent(tree, val, sel, expand, leaf, row, hasFocus);
    // sets Icons
    setLeafIcon(leafIcon);
    setClosedIcon(new ImageIcon("Folder95C.gif"));
    setOpenIcon(new ImageIcon("Folder95O.gif"));
    // set Expansion icons to + -
    ComponentUI treeUI = tree.getUI();
    if(treeUI instanceof BasicTreeUI) {
    ((BasicTreeUI)treeUI).setExpandedIcon(new ImageIcon("minus.gif"));
    ((BasicTreeUI)treeUI).setCollapsedIcon(new ImageIcon("plus.gif"));
    // decides who icon to use
    if(leaf && isSecuredFile(value)) {
    setLeafIcon(leafSecuredIcon);
    setToolTipText("This file is Secured Access Only");
    else {
    setToolTipText(null);
    return this;
    protected boolean isSecuredFile(Object value) {
    DefaultMutableTreeNode node = (DefaultMutableTreeNode)value;
    NodeRecord nodeInfo = (NodeRecord)(node.getUserObject());
    String nodeTitle = nodeInfo.NodeRecord;
    if(nodeTitle.indexOf("DOM") >= 0) {
    return true;
    return false;
    }

Maybe you are looking for

  • How do I create a duplicate iPhoto library as a running backup on 2 external drives?

    I have moved my iPhoto library onto an external hard drive, but I want to create a backup of iPhoto on an additional external hard drive.  My library is too big to keep on my Macbook SSD. I plan to keep a Carbon Copy Clone going to keep both of my iP

  • Home movies watchable on Apple TV?

    I'm considering buying the Apple TV and I was wondering if I could view my own personal videos on it. These are the video formats I usually work with: AVI FLV DIVX MOV MP4 Can I view these on on apple tv or is it exclusive to content purchased via iT

  • Dreamweaver/Contribute/CSS issues

    Anyone run into issues when creating a site with Dreamweaver and an external CSS and having information edited in Contribute add in-line styles? It is a pain in the rear to continually go back and edit out the in-line styles when the purpose of using

  • Crashed while woke up from hibernate

    My macbook pro 13 2012-mid crashed when i tried to wake it up from hibernate. It freezes at login. I am using OS X 10.9.4 , and i replaced my superdrive to a new SSD plextor m6s 256GB, and modified ram to 16GB (2 8GB rams) here's the system report: S

  • Iphone 4s turning to blue

    MY iphone 4s the screen was totally blue i turn it off and when switch on they turn to blue ,how can i manage this please,could you help me about this