Select Expanded nodes in JTree

Hi all,
In the given tree structure, I want to get a node to be selected, once it is expanded.
+ Folder1
- Folder2
      |
      |__-Folder3
       |
       |__-Folder4
          |
            |__ file1.docCurrently, if I have Folder1 selected and if I expand Folder2, the selection remains at
Folder1 itself. I need to change the selection to Folder2.
Also, I need to get the path of the expanded node . ie; when Folder4 is expanded, I need to
get Folder4 selected and path has to be obtained as \Folder2\Folder3\Folder4.
I found this link helpful-- http://forums.sun.com/thread.jspa?messageID=3616726, but there
also, the path is obtained based on selection and not based on expansion.
Please help with a solution
Regards,
Anees

AneesAhamed wrote:
Hi all,
In the given tree structure, I want to get a node to be selected, once it is expanded.
+ Folder1
- Folder2
|
|__-Folder3
       |
       |__-Folder4
          |
            |__ file1.docCurrently, if I have Folder1 selected and if I expand Folder2, the selection remains at
Folder1 itself. I need to change the selection to Folder2.
Also, I need to get the path of the expanded node . ie; when Folder4 is expanded, I need to
get Folder4 selected and path has to be obtained as \Folder2\Folder3\Folder4.
I found this link helpful-- http://forums.sun.com/thread.jspa?messageID=3616726, but there
also, the path is obtained based on selection and not based on expansion.
Please help with a solution
Regards,
AneesTo expand any node you need to "know" it either due to a user's mouse click or inside the code that expands it directly, something like :
- by mouse click :
myJTree.addMouseListener(new MouseAdapter()
     public void mouseClicked(MouseEvent e)
          TreePath treePath = getPathForLocation(e.getX(), e.getY());
});- direct code :
public void treeWillExpand(TreeExpansionEvent e)
     TreePath treePath = e.getPath();
}Then you can get the corresponding node from the TreePath :
DefaultMutableTreeNode node = (DefaultMutableTreeNode)treePath.getLastPathComponent();But for a selection this should be enough :
myJTree.setSelectionPath(treePath);
myJTree.scrollPathToVisible(treePath);Regards,
Lara.

Similar Messages

  • Expanding nodes in JTree

    I have an application that uses JTree
    I create the Jtree but I want to expand to see and select a node.
    I have the object of the node and the TreePath but I can't expand the tree using expandPath(), makeVisible(), scrollPathToVisible(path), etc. It seems that JTree doesn't detect the path I use as input.
    But when I use setSelectionPath(path) it is selected (I know because I see information about the node) but it is not displayed nor viewable.
    I only can expand nodes using expandRow(int).
    Does anybody know how expand and select nodes without clicking with mouse?

    expandPath(Treepath treePath) should work. Its possible that your treePath is wrong. How do you get the treePath?

  • Positioning expanded nodes on JTree

    Hey all,
    Does anyone know how to position an expanded node on a JTree to scroll inwards to the right (towards the current expanded level) and move to the top of the Panel it sits in? Kinda like Windows explorer.
    Any help will be greatly appreciated. Thanks in advance,
    zia

    Try to use
    setScrollsOnExpand(boolean�newValue) method of JTree
    regards
    Stas

  • JTree and selected tree node

    I am allowing the user to search for a node in a JTree. I can find the node and progamatically expand and select the node. What I would like to do next is find the x,y coordinates of this selected node so I can use Robot to move the mouse to this node. I have hover help which is chock full of information in HTML describing this node, however, the user now is required to move the cursor to this selected node to see the hover help.
    Any help would be appreciated.

    Hi ,
    try this
    jlabel.setIcon( null ) ;

  • Trouble with JTree's and autmoatically expanding nodes

    I am writing an application which uses a JTree as a method of browsing through a certain structure (like a file system). I am having a little trouble though, with a number of small issues, which I am finding hard to get answers through searches (and have spent a fair while searching). In navigating the tree, I want to be able to automatically expand nodes.
    Firstly, I want the Root node to automatically be expanded. I cannot see ways of doing this. I have seen references to EXPANDED being set for the JTree constructor, but I cannot see any reference in the 1.6 API for this.
    Secondly, I want to be able to expand or hide the contents of nodes through other means than clicking on the icon to the left of a non-leaf-node. For example a button that would hide the contents of (i.e. close) the currently selected node. Code such as:
    myNode.setExpanded(true);
    myNode.setExpanded(false);and
    myNode.isExpanded();

    That's the ticket - again something I had seen, but had been using in the wrong way, but your suggestion has helped me get it right. I was trying to expand the path before any more nodes were added to the root node. Then nodes are added, and the application loaded with the root node collapsed. So now I have placed the call at the end of the recursive call to populate the tree.
    Thanks again.

  • Selectable JTable as leaf node in JTree

    I've created a TreeCellRenderer that renders a JTable for nodes of type TableNode. The actual rendering seems to work fine, but the problem is that I am unable to select the rows in the JTable. I tried using a JTable-based TreeCellEditor, but that wasn't what I needed either. I don't need to edit the data, but only select an individual row so I can get its data to display in another panel on the screen.
    Any ideas?
    private class TableTreeCellRenderer extends DefaultTreeCellRenderer {
       private JTable table = new JTable();
       private DefaultTableModel model = (DefaultTableModel) table.getModel();
       public Component getTreeCellRendererComponent(JTree tree,
                                            Object value,
                                            boolean selected,
                                            boolean expanded,
                                            boolean leaf,
                                            int row,
                                            boolean hasFocus) {
         if (value instanceof TableNode) {
               TableNode node = (TableNode) value;
            model.setDataVector(node.getData(), node.getHeaders());
            JScrollPane js = new JScrollPane(table);
            js.setPreferredSize(getTableSize(table));
            return js;
         return super.getTreeCellRendererComponent(tree,
                                                      value,
                                          selected,
                                          expanded,
                                          leaf,
                                          row,
                                          hasFocus);
       private Dimension getTableSize(JTable table) {
          return null;
    }

    A renderer isn't a component which is added to a parent (tree in this case). It is only used for display purposes. You might try a [url http://java.sun.com/products/jfc/tsc/articles/treetable1/index.html]TreeTable.

  • How to show only all children of selected node in JTree??

    Dear friends:
    I have Two Panels, PA and PB,
    PA has a Jtree as code below, and PB listens to PA,
    I hope to do following,
    If I select a node called A in PA, then Node A's all children such as A1, A2, A3 will be displayed in PB, but not display A1, A2, A3's children such as A3 has C1, C2, C3, C4 & C5, until I select A3 then PB will display only all A3's children: C1, C2, C3, C4 & C5;
    i.e, only populate each ONE level of children of Node A or any node I select, not its grandchildren and its grand-grand children;
    Please help how to do it??
    I tried amny times, failed.
    Thanks
    [1]. PA panel code:
    package com.atest;
         import java.awt.BorderLayout;
         import java.awt.event.MouseAdapter;
         import java.awt.event.MouseEvent;
         import java.util.Enumeration;
         import java.awt.Dimension;
         import javax.swing.JFrame;
         import javax.swing.JPanel;
         import javax.swing.JScrollPane;
         import javax.swing.JTextField;
         import javax.swing.JTree;
         import javax.swing.tree.DefaultMutableTreeNode;
         import javax.swing.tree.TreeModel;
         import javax.swing.tree.TreePath;
         public class DefaultMutableTreeMain extends JPanel {
         protected DefaultMutableTreeNode    top = new DefaultMutableTreeNode("Options");
         protected DefaultMutableTreeNode      selectedNode = null;
         protected final JTree tree;
         protected final JTextField jtf;
        protected Enumeration      vEnum = null;
         private      TreeModel                m;
         protected  DefaultMutableTreeNode      getDefaultMutableTreeNode()  {
              //textArea.getText();
                   return selectedNode;
         protected  DefaultMutableTreeNode setDefaultMutableTreeNode(DefaultMutableTreeNode tt)  {
              //textArea.getText();
                   selectedNode = tt;
                   return selectedNode;
         protected  TreeModel getJTModel()  {
              //textArea.getText();
                   return m;
         protected  TreeModel setJTModel(TreeModel ta)  {
                   m = ta;
                   return m;
           public DefaultMutableTreeMain() {
             setSize(300,300);
             setLayout(new BorderLayout());
             DefaultMutableTreeNode a = new DefaultMutableTreeNode("A");
             top.add(a);
             DefaultMutableTreeNode a1 = new DefaultMutableTreeNode("A1");
             a.add(a1);
             DefaultMutableTreeNode a2 = new DefaultMutableTreeNode("A2");
             a.add(a2);
             DefaultMutableTreeNode a3 = new DefaultMutableTreeNode("A3");
             a.add(a3);
             DefaultMutableTreeNode b = new DefaultMutableTreeNode("B");
             top.add(b);
             DefaultMutableTreeNode b1 = new DefaultMutableTreeNode("B1");
             b.add(b1);
             DefaultMutableTreeNode b2 = new DefaultMutableTreeNode("B2");
             b.add(b2);
             DefaultMutableTreeNode b3 = new DefaultMutableTreeNode("B3");
             b.add(b3);
             DefaultMutableTreeNode c = new DefaultMutableTreeNode("C");
             a3.add(c);
             DefaultMutableTreeNode c1 = new DefaultMutableTreeNode("C1");
             c.add(c1);
             DefaultMutableTreeNode c2 = new DefaultMutableTreeNode("C2");
             c.add(c2);
             DefaultMutableTreeNode c3 = new DefaultMutableTreeNode("C3");
             c.add(c3);
             DefaultMutableTreeNode c4 = new DefaultMutableTreeNode("C4");
             c.add(c4);
             DefaultMutableTreeNode c5 = new DefaultMutableTreeNode("C5");
             c.add(c5);
             tree = new JTree(top);
             JScrollPane jsp = new JScrollPane(tree);
             jsp.setPreferredSize(new Dimension(400,300));
             add(jsp, BorderLayout.CENTER);
             jtf = new JTextField("", 20);
             add(jtf, BorderLayout.SOUTH);
               tree.addMouseListener(new MouseAdapter() {
               public void mouseClicked(MouseEvent me) {
                  TreePath   path = tree.getSelectionPath();
                  DefaultMutableTreeNode      selectedNode = (DefaultMutableTreeNode)path.getLastPathComponent();
                 TreePath tp = tree.getPathForLocation(me.getX(), me.getY());
                 setDefaultMutableTreeNode(selectedNode);
                     System.out.println("Current node selected is (tp.toString()=" + tp.toString());
                     System.out.println("Current node selected is getDefaultMutableTreeNode()=" + getDefaultMutableTreeNode());
                 if (tp != null){
                     jtf.setText(tp.toString());
                      System.out.println("It Has Children as selectedNode.getChildCount()= " + selectedNode.getChildCount());
                            Enumeration vEnum = selectedNode.children();
                                int i = 0;
                                while(vEnum.hasMoreElements()){
                                    System.out.println("2 selectedNode = " +  path.toString() + "  has " + i++ + " Children in vEnum.nextElement(" + i + ") = " + vEnum.nextElement());
                 else
                   jtf.setText("");
           public static void main(String[] args) {
             JFrame frame = new JFrame();
             frame.getContentPane().add(new DefaultMutableTreeMain());
             frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
             frame.setSize(400, 400);
             frame.setVisible(true);
         }[2]. PB Panel code
    package com.atest;
    import java.awt.BorderLayout;
    import javax.swing.JScrollPane;
    import javax.swing.JTree;
    import javax.swing.JPanel;
    import javax.swing.event.TreeSelectionEvent;
    import javax.swing.event.TreeSelectionListener;
    import javax.swing.tree.*;
    import javax.swing.JButton;
    import javax.swing.tree.DefaultMutableTreeNode;
    import javax.swing.tree.DefaultTreeModel;
    import javax.swing.tree.TreePath;
    public class DefaultMutableTreeSub extends JPanel implements java.io.Serializable{
      private JButton removeButton;
      private JButton addButton;
      JTree tree;
      private TreeModel      m;
      protected TreeDragSource ds;
      protected TreeDropTarget dt;
    protected  TreeModel getJTModel()  {
              //textArea.getText();
                   return m;
    protected  TreeModel setJTModel(TreeModel ta)  {
                   m = ta;
                   return m;
    protected DefaultTreeModel model;
    protected DefaultMutableTreeNode rootNode;
    DefaultMutableTreeMain dmm = null;
    JPanel inputPanel  = new JPanel();
      public JPanel SLTreeDNDEditableDynamic(DefaultMutableTreeMain tdnd ) {
        //super("Rearrangeable Tree");
        setSize(400,450);
        dmm = tdnd;
             setLayout(new BorderLayout());
             inputPanel.setLayout(new BorderLayout());
             JPanel outputPanel = new JPanel();
             System.out.println("Sub selectedNode tdnd= " + tdnd);
             tdnd.tree.addTreeSelectionListener(new TreeSelectionListener(){
                  public void valueChanged(TreeSelectionEvent evt){
                  TreePath[] paths = evt.getPaths();
                  TreePath   path = dmm.tree.getSelectionPath();
                  DefaultMutableTreeNode      selectedNode = (DefaultMutableTreeNode)path.getLastPathComponent();
                 DefaultMutableTreeNode itemNode = dmm.getDefaultMutableTreeNode();
                     System.out.println("Sub node selected is dmm.getDefaultMutableTreeNode()=" + dmm.getDefaultMutableTreeNode());
                  model = new DefaultTreeModel(itemNode);
                  tree = new JTree(model);
                  System.out.println("Sub selectedNode paths= " + paths);
                  System.out.println("Sub selectedNode path= " + path);
                  System.out.println("Sub selectedNode = " + selectedNode);
                  System.out.println("Sub itemNode = " + itemNode);
                  tree.putClientProperty("JTree.lineStyle", "Angled");
                  tree.setRootVisible(true);
                   inputPanel.add(new JScrollPane(tree),BorderLayout.CENTER);
             return inputPanel;
         public DefaultMutableTreeSub() {
              super();
    }thanks
    sunny

    Thanks so much, I use your code and import followig:
    import java.util.ArrayList;
    import java.awt.List;
    but
    private static List<Object> getChildNodes(JTree j) {
         Object parent = j.getLastSelectedPathComponent();
         int childNodeCount = j.getModel().getChildCount(parent);
         List<Object> results = new ArrayList()<Object>;
         for (i = 0; i < childNodeCount; i++) {
              results.add(parent, i);
         return results;
    here List<Object> and ArrayList()<Object> show red,
    Is my JDK version problem??
    my one is JKD
    C:\temp\swing>java -version
    java version "1.4.2_08"
    Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_08-b03)
    Java HotSpot(TM) Client VM (build 1.4.2_08-b03, mixed mode)
    Error as follows:
    C:\temp\swing>javac DefaultMutableTreeSub.java
    DefaultMutableTreeSub.java:38: <identifier> expected
    private static List<Object> getChildNodes(JTree j) {
    ^
    1 error
    any idea??
    Thanks

  • Select multiple nodes in a JTree a right click

    Hi all,
    I've a JTree and I'd like to allow the user select some nodes (one or more) right click and than show a popupMenu.
    This behavior seems not to be easy, because if I select a single node (right clicking on it) the node does not appear selected ; I need to select it left clicking and than everything works fine.
    I read some posts found in the forum and the solution seems to be :
    - attach a mouseListener to the JTree
    - get the TreePath of the node selected
    - force the selection on the node with setSelectionPath(TreePath)
    This works fine if you need to select only one node, cause if you have to select more, you simply cannot.
    I wonder a so obvious behavior is so hard to achieve.
    I hope somebody out there had made the magic.
    Any help would be appreciated.
    Flavio Palumbo

    Hi Darryl,
    I wrote the test case below.
    Using the methods you suggested it works almost fine.
    The only behavior not desired is when you select a range (shift or control), release the key an than right click ; in this case remains selected the only node you clicked on ; to select the range clicking with the right button, you have to keep pressed the key.
    Any hint would be appreciated.
    Flavio
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.MouseAdapter;
    import java.awt.event.MouseEvent;
    import javax.swing.JFrame;
    import javax.swing.JMenuItem;
    import javax.swing.JPopupMenu;
    import javax.swing.JTree;
    import javax.swing.SwingUtilities;
    import javax.swing.tree.DefaultMutableTreeNode;
    import javax.swing.tree.DefaultTreeModel;
    import javax.swing.tree.TreePath;
    public class TestTree {
        JTree jtr = null;
        public static void main(String[] args) {
            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    new TestTree();
        public TestTree() {
            JFrame jf = new JFrame();
            jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            try {
                javax.swing.UIManager.setLookAndFeel(javax.swing.UIManager.getSystemLookAndFeelClassName());
                javax.swing.SwingUtilities.updateComponentTreeUI(jf);
            } catch (Throwable e) {
            jf.setPreferredSize(new java.awt.Dimension(200, 560));
            javax.swing.JScrollPane js = new javax.swing.JScrollPane();
            DefaultMutableTreeNode root = new DefaultMutableTreeNode("root");
            jtr = new JTree(root);
            jtr.addMouseListener(new TestTreeML());
            js.setViewportView(jtr);
            jf.getContentPane().add(js);
            for (int i = 0; i < 20; i++) {
                DefaultMutableTreeNode nodoFiglio = new DefaultMutableTreeNode("nodo" + i);
                ((DefaultTreeModel) jtr.getModel()).insertNodeInto(nodoFiglio, root, root.getChildCount());
            jf.pack();
            jf.setVisible(true);
        public class TestTreeML extends MouseAdapter {
            @Override
            public void mousePressed(MouseEvent e) {
            @Override
            public void mouseClicked(MouseEvent e) {
                try {
                    if (!e.getSource().equals(jtr)) {
                        return;
                    TreePath tpSel = jtr.getPathForLocation(e.getX(), e.getY());
                    if (tpSel == null) {
                        return;
                    int i = 0;
                    final DefaultMutableTreeNode node = (DefaultMutableTreeNode) tpSel.getLastPathComponent();
                    TreePath[] tpExisting = null;
                    if (e.isControlDown() || e.isShiftDown()) {
                        System.out.println("control/shift");
                        TreePath[] tpEx = jtr.getSelectionPaths();
                        tpExisting = java.util.Arrays.copyOfRange(tpEx, 0, tpEx.length + 1);
                        i = tpEx.length;
                    } else {
                        tpExisting = new TreePath[1];
                    tpExisting[i] = tpSel;
                    jtr.setSelectionPaths(tpExisting);
                    if (e.getClickCount() == 2) {
                        System.out.println("double click on " + node.getUserObject());
                    if (javax.swing.SwingUtilities.isRightMouseButton(e)) {
                        if (!e.isControlDown()) {
                            jtr.setSelectionPath(tpSel);
                        JPopupMenu menu = new JPopupMenu();
                        JMenuItem it0 = new JMenuItem("Option1");
                        it0.addActionListener(new ActionListener() {
                            public void actionPerformed(ActionEvent e) {
                                System.out.println("Option1 on " + node.getUserObject());
                        menu.add(it0);
                        JMenuItem it1 = new JMenuItem("Option2");
                        it1.addActionListener(new ActionListener() {
                            public void actionPerformed(ActionEvent e) {
                                System.out.println("Option2 on " + node.getUserObject());
                        menu.add(it1);
                        menu.show(jtr, e.getX(), e.getY());
                } catch (Throwable t) {
    }

  • 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 allow multiple selection of nodes in a JTree

    How to allow multiple selection of nodes in a JTree ?
    Thanks
    S.Satish

    By default when you create new instance og JTree the selection model is multiple selection. And if you want to change it you use next:
    tee.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    or
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.CONTIGUOUS_TREE_SELECTION);
    or
    tree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
    Hope will help!

  • How to select node in JTree without firing event?

    I have got standard situation. JTree in the left panel, and several edit boxes in right panel. Certainly, I have TreeSelectionListener, which on every tree node selection shows corresponding model values in edit boxes.
    I'd like to implement next logic:
    1. Something was changed in any edit box in right panel. Model has been changed.
    2. User clicks on different node in tree.
    3. Dialog "Message was not saved. Save?" with Yes/No/Cancel buttons are shown.
    Yes/No buttons are easy to handle.
    Question is about Cancel. I'd like on Cancel button left all edit boxes in their present state (do not restore values from saved model) and select back node, which wasn't saved.
    Problem is next. If I select node by setSelectionPath or smth like that, but... JTree fires event and my listener receives onTreeItemSelected back, which checks that node wasn't saved and ......
    Who does have any idea, or have done similar tasks? How can I select node and do not allow tree fire event this time?
    Thanks in advance.

    First, as soon as the model changes (when editing any
    combo box) some flag will be set. Now the logic which
    updates the combo boxes will do it only on a change of
    the current node and (this is new) if the flag wasn't
    set. You should have some flag anyway because somehow
    you must determine when to show the dialog, shouldn't
    you?Yes, I have got this logic implemented. But it's only the half :)
    I know exactly when my model has been changed, but if it was changed, i'd like to ask user what to do next - svae/loose changes/cancel
    And on cancel i'd like to select last edited tree node and do not get event from tree at that moment.
    >
    Second way, prevent selecting a new node if that flag
    has been set. You could do this by subclassing
    DefaultTreeSelectionModel and overriding some methods
    (setSelectionPath() et al).Ok. I'll investigate this.
    >
    MichaelThanks.

  • Coloring selected nodes in JTree

    i am currently using setCellRenderer() for highlighting a selected node in my JTree.but when i select another node, the previously selected node loses its highlight.i would like to know of how i could make the highlight in the selected nodes remain persistent.

    I am currently using DISCONTIGUOUS_TREE_SELECTION only. my requirement is that i should be able to select any number of nodes.so i use this selection.
    but at the same time, my highlight in selected nodes should be like a toggle-state.
    if i select an already selected node ( say A), the highlight has to go away.
    and at the same time, th highlight on previously selected nodes (say B, C) should be persistent.
    am currently using TreeSelectionListener. and for rendering am using SetCellRenderer.
    in this scenario, how could my work be accomplished?

  • How to select a node in a JTree by name

    I have a JTree in my program. I want to programmatically set one of these nodes selected by the name of the node. I do not know how to do this. I read the "How to use trees", but no help
    Thanks!

    I have a JTree and each node on the JTree has a string name. I also have a JEditorPane that lists all these names at start up. If the user clicks on one of these names, I want to catch the HyperlinkEvent and automatically select that node in the JTree.
    So in short, I have the String name of the node that I want to programatically select.
    Thanks!

  • Setting custom color for selected node in JTree?

    Hi,
    i want to set my own color for selected node in JTree. i don't want to set for all the nodes...how to set Color for Selected node using TreeCellRender class?
    Thanks
    Mani

    I assume you are not setting a custom tree cell renderer...
    javax.swing.JTree theTree = ...;
    java.awt.Color newBGColor = ...;
    ((javax.swing.tree.DefaultTreeCellRenderer)theTree.getCellRenderer())
        .setBackgroundSelectionColor(newColor);

  • Selecting a node in a JTree knowing his path

    Hello for all,
    I'm trying to select a specific node in a JTree component by clicking a button.. this is my code :
    private DefaultMutableTreeNode treeNode = new DefaultMutableTreeNode("root");
    private DefaultTreeModel treeModel = new DefaultTreeModel(treeNode);
    private JTree tree = new JTree(treeModel);
    private JButton button = new JButton("Select");
    DefaultMutableTreeNode child1 = new DefaultMutableTreeNode("child1");
    DefaultMutableTreeNode child2 = new DefaultMutableTreeNode("child2");
    child1.add(new DefaultMutableTreeNode("child11"));
    treeNode.add(child1);
    treeNode.add(child2);
    button.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        TreePath path = new TreePath(new Object[]{"root", "child1"});               
        tree.setExpandsSelectedPaths(true);
        tree.scrollPathToVisible(path);
    });as you can see, I want to select the node with the path "root/child1"..
    but I'm getting this exception : Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: java.lang.String cannot be cast to javax.swing.tree.TreeNode..
    any ideas ?

    You will want to read the second sentence in the TreePath comments section.
    Also, read the second sentence in the TreePath Method Detail section for the
    getLastPathComponent method.
    With these clues &#8212; try getting a TreePath from the tree you are working with.
    For example, you can try something like tree.getPathForRow(row) using the
    visible row index of "child1". Since the TreePath returned comes from the tree
    it will understand what to do with it. You can check the class name of the
    components that are returned in the TreePath to confirm this. And it will
    explain the exception you quoted.

Maybe you are looking for

  • Podcasts and Multiple iPods on the same Windows PC

    Hi there, I have iTunes (6.04) on a Windows XP machine (I would use my powerbook G4 but its hard drive isn't big enough!) I have two iPod nanos (one mine, one my girlfriend's) which sync with this iTunes and it works well except for a small glitch. I

  • How to cancel downloads

    I would prefer not to receive the HD versions of tv downloads.  They take up way too much space on my drive.  Is there any way to prevent the initial download?  I am currently coping by simply deleting the files once downloaded.

  • Errors when running the test_fwktutorial.jsp

    I am trying to run the test_fwktutorial.jsp according to the instructions in the OA Documentation. I am getting the following message. I tried all the things given in this forum but its still giving the same problem. Please help oracle.apps.fnd.frame

  • Can I listen to my audio books with my bluetooth earpiece on my iphone 4S?

    Can I listen to my audio books with my bluetooth earpiece on my iphone 4S?

  • InCopy CS4 font problems

    We're working on a document and having some issues because of fonts. The designer is on InDesign on a mac and I'm on InCopy on PC. Unfotunately, one of the fonts she chose isn't cross-platform and we don't want to spend the money to get a cross platf