JTree RootHandles and TreeSelectionListener

Hello!
I have the following problem
I create a tree using vector( the vector contains other vectors etc).
I also create a TreeSelectionListener that when I select the leafs of this tree,leafs to become nodes,expand and contain new leafs.
Unfortunately,when I use it, the listener is triggered only when I click
on the icons I use. If I click on the roothandle in front of the icon it does nothing and the roothandle disappears.I think this happens because it remains leaf.
Why the two clicks differ?
How can I make the roothandle to trigger with the listener?

Try this:
jt.addTreeWillExpandListener(new TreeWillExpandListener() {
    public void treeWillCollapse(TreeExpansionEvent e) {
    public void treeWillExpand(TreeExpansionEvent e) {
        // The tree
        JTree tree = (JTree) e.getSource();
        // Get parent of node that will be expanded
        TreePath path = e.getPath();
        TreeNode node = (TreeNode) path.getLastPathComponent();
        TreeNode parent = node.getParent();
        // Get nodes of path
        Object[] pathNodes = path.getPath();
        int lastNode = pathNodes.length - 1;
        // Find currently open node under parent
        Enumeration enum = parent.children();
        while ( enum.hasMoreElements() ) {
            DefaultMutableTreeNode kid = (DefaultMutableTreeNode)
                enum.nextElement();
            // Get path to kid
            pathNodes[lastNode] = kid;
            TreePath kidPath = new TreePath( pathNodes );
            if ( tree.isExpanded( kidPath ) ) {
                // Collapse this node
                tree.collapsePath( kidPath );
                // Remove its kids
                kid.removeAllChildren();
                // Add in dummy node so it still has kids
                DefaultMutableTreeNode placeholder = new
                    DefaultMutableTreeNode( "placeholder" );
                kid.add( placeholder );
                // Let model know it has changed
                ( (DefaultTreeModel) tree.getModel() ).
                    nodeStructureChanged( kid );
                // Done here
                break;
});

Similar Messages

  • JTree, JList and file selection

    I have a file selection JPanel that I'm creating that has a JTree on the left representing folders and a JList on the right that should have the files and folders listed to be able to select. I have two problems at this point. First, and more important, when a folder is selected, the JList doesn't update to the files in the new folder and I don't see what's keeping it from working. Second, when clicking on a folder in the JTree, it drops the folder to the end of the list and then lets you expand it to the other folders, also it shows the whole folder path instead of just the folder name.
    This is still my first venture into JTrees and JLists and I'm still really new at JPanel and anything GUI, so my code may not make the most sense, but right now I'm just trying to get it to work.
    Thank you.
    public class FileSelection extends JFrame{
              Container gcp = getContentPane();
              File dir=new File("c:/");
              private JList fileList;
              JTree tree;
              DefaultMutableTreeNode folders;
              String filePath,selectedFile="", path;
              TreePath selPath;
              FileListPanel fileLP;
              FolderListPanel folderLP;
              JScrollPane listScroller;
              public FileSelection(String name){
                   super(name);
                   gcp.setLayout(new BorderLayout());
                   fileLP = new FileListPanel();
                   folderLP = new FolderListPanel();
                   gcp.add(fileLP, BorderLayout.CENTER);
                   gcp.add(folderLP, BorderLayout.WEST);
                   setVisible(true);
              private class FileListPanel extends JPanel implements ActionListener{
                   public FileListPanel(){
                        final JButton selectItem = new JButton("Select");
                        final JButton cancel = new JButton("Cancel");
                        final JButton changeDir = new JButton("Change Directory");
                        //add buttons
                        add(selectItem);
                        add(changeDir);
                        add(cancel);
                        //instantiate buttons
                        selectItem.setActionCommand("SelectItem");
                        selectItem.addActionListener(this);
                        changeDir.setActionCommand("ChangeDirectory");
                        changeDir.addActionListener(this);
                        cancel.setActionCommand("Cancel");
                        cancel.addActionListener(this);
                        final String[] fileArr=dir.list();
                        fileList = new JList(fileArr);
                        fileList.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
                        fileList.setLayoutOrientation(JList.VERTICAL_WRAP);
                        fileList.setVisible(true);
                        fileList.setVisibleRowCount(-1);
                        fileList.setSelectedIndex(0);
                        listScroller = new JScrollPane(fileList);
                        listScroller.setPreferredSize(new Dimension(200,200));
                        listScroller.setAlignmentX(LEFT_ALIGNMENT);
                        add(listScroller);
                        MouseListener mouseListener = new MouseAdapter(){
                             public void mouseClicked(MouseEvent e){
                                  if(e.getClickCount()==2){
                                       int itemIndex = fileList.locationToIndex(e.getPoint());
                                       currFile=fileArr[itemIndex];
                                       dispose();
                        fileList.addMouseListener(mouseListener);
                   public void actionPerformed(ActionEvent e){
                        if("SelectItem".equals(e.getActionCommand())){
                             currFile=(String)fileList.getSelectedValue();
                             dispose();
                        }else{
                        if("Cancel".equals(e.getActionCommand())){
                             dispose();
                        }else{
                        if("ChangeDirectory".equals(e.getActionCommand())){
                             ChangeDir cd = new ChangeDir("Select Directory");
                             cd.setSize(new Dimension(300,275));
                             cd.setLocation(500, 225);
              private class FolderListPanel extends JPanel{
                   public FolderListPanel(){
                        String[] files = dir.list();
                        DefaultMutableTreeNode topNode = new DefaultMutableTreeNode("Files");
                        folders = new DefaultMutableTreeNode("C:/");
                        topNode.add(folders);
                        folders = getFolders(dir, folders);
                        tree = new JTree(topNode);
                        tree.setVisible(true);
                        JScrollPane treeScroller = new JScrollPane(tree);
                        treeScroller.setPreferredSize(new Dimension(500,233));
                        treeScroller.setAlignmentX(LEFT_ALIGNMENT);
                        add(treeScroller);
                        MouseListener mouseListener = new MouseAdapter(){
                             public void mouseClicked(MouseEvent e){
                                  try{
                                       if(e.getClickCount()==1){
                                            selPath = tree.getPathForLocation(e.getX(), e.getY());
                                            path=selPath.getLastPathComponent().toString();
                                            dir = new File(path);
                                            TreeNode tn=findNode(folders, path);                    
                                            if(tn!=null){
                                                 folders.add((MutableTreeNode) getTreeNode(dir, (DefaultMutableTreeNode) tn));
                                            tree.updateUI();
                                            final String[] fileArr=dir.list();
                                            fileList = new JList(fileArr);
                                            fileList.updateUI();
                                            listScroller.updateUI();
                                            fileLP = new FileListPanel();
                                  }catch(NullPointerException npe){
                        tree.addMouseListener(mouseListener);
                   public DefaultMutableTreeNode getFolders(File dir, DefaultMutableTreeNode folders){
                        File[] folderList = dir.listFiles();
                        int check=0;
                        for(int x=0;x<folderList.length;x++){
                             if(folderList[x].isDirectory()){
                                  folders.add(new DefaultMutableTreeNode(folderList[x]));               
                        return folders;
                   public TreeNode getTreeNode(File dir, DefaultMutableTreeNode folders){
                        File[] folderList = dir.listFiles();
                        int check=0;
                        for(int x=0;x<folderList.length;x++){
                             if(folderList[x].isDirectory()){
                                  folders.add(new DefaultMutableTreeNode(folderList[x]));               
                        return folders;
                   public TreeNode findNode(DefaultMutableTreeNode folders, String node){
                        Enumeration children = folders.postorderEnumeration();
                        Object current;
                        while(children.hasMoreElements()){
                             current = children.nextElement();
                             if(current.toString().equals(node)){
                                  return (TreeNode)current;
                        return null;
         }

    Wow! I changed the FolderListPanel's mouseListener to:
    tree.addTreeSelectionListener(new TreeSelectionListener(){
                             public void valueChanged(TreeSelectionEvent tse){
                                  DefaultMutableTreeNode node = (DefaultMutableTreeNode)tree.getLastSelectedPathComponent();
                                  if(node==null)return;
                                  Object nodeInfo = node.getUserObject();
                                  dir=new File(nodeInfo.toString());
                                  folders.add((MutableTreeNode) getFolders(dir,node));
                        });and it's amazing how much better the tree is!!! But I still don't have the JList part working. I changed the JList and the FileListPanel to public from private, but that didn't change anything.

  • JPopupMenu for a JTree, enabling and disabling options

    Hi all.
    I'm trying to activate/deactivate some JMenuItem options for a JPopupMenu launched for a JTree object.
    Let's say, depending on "some state", I want some options in the JPopupMenu (the JMenuItems) should be enabled or disabled, and change whenever that state changes.
    I'm trying to activate this feature with "((JMenuItem) item).setEnabled(true)" but the PopupMenu option is still disabled.
    Can some one help me, please?
    Thanks a lot in advance.
    -- Arturo

    Hi all.
    I'm trying to activate/deactivate some JMenuItem options for a JPopupMenu launched for a JTree object.
    Let's say, depending on "some state", I want some options in the JPopupMenu (the JMenuItems) should be enabled or disabled, and change whenever that state changes.
    I'm trying to activate this feature with "((JMenuItem) item).setEnabled(true)" but the PopupMenu option is still disabled.
    Can some one help me, please?
    Thanks a lot in advance.
    -- Arturo

  • JTree Drag and Drop (Multi Nodes)

    Hi All!
    I have been searching the forums for a few hours over the last few days and have found some nice examples and explanations on how to implement drag and drop for a jtree.
    However, I would love to know how this is accomplished when selecting multiple nodes.
    I want to be able to see all the selected nodes being dragged...
    Anyone implemented anything of the sort... or even just knows how to do this?
    Thanks in advance!!
    Aaron.

    When you drag get the [x,y] mouse position and use the JTree method:
    getRowForLocation(x, y) for node you at the also for the parent node location of the child node.
    Once the childY is less than childParentY, you stop the drag.
    Hope that helps?

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

  • JTree, BC4J and self referenced table

    Hello.
    table OBJECTS which has a primary key ID and a parent ref PARENTID.
    This is to have a tree structure of objects.
    I want that viewed in a JTree structure (using jclient and bc4j's)
    How do i do that? if i do the obvious and use the object view with itself as accessor,
    The tree is fine except ALL objects are stored on the rootlevel (of course).
    Is there a way to make a polymorphic restriction only on root level, or do I use two viewobjects to represent the data? (and how would i do that the right way?)
    Or is there another way?
    Thanks.

    Is there a way to make a polymorphic restriction only on root level, or do I use two viewobjects to represent the data? (and how would i do that the right way?)No you should not have to use Two different VOs. See a discussion on OTN thread:
    Re: LDAP Authentication and DB user

  • JTree drag and drop

    Hi.. How can I drag and drop items from one JTree to another??? thanks!!!

    The following link might help you :
    http://forum.java.sun.com/thread.jspa?forumID=57&threa
    dID=296255Thanks! this thread has been useful. How can I manipulate the code so that I can have two different trees instead of just one tree? How can I make the drag and drop one-way???

  • JTree Drag and Drop question

    I have drag and drop working fairly well using jdk 1.4. I'm able to copy and move objects around in the tree and change the cursor as it moves over various objects in the tree. The only problem I'm having is when the user drops something into someplace that rejects the drop, for instance in the blank area of the JTree object. In this case, the drop never seems to complete. If I try to drag that same object again it throws an InvalidDnDOperationException saying that a DnD operation is already in progress. I noticed that the drop() operation is not being called when the user drops the object into a rejected area.
    I've searched the forums and haven't seen anyone else report this problem. Does anyone have any suggestions?

    I'd love it too if you would send me you code, or post it so others can benefit; there seems to be quite a number of people who want DnD JTree functionality. I've been going nuts trying to figure out the best way to implement DnD on a JTree. I started using the new TransferHandler and had reasonable success with it. But, I'm not sure how to get the cursor to change based on DropTarget (not all nodes are created equal in this regard). I need access to the DragSourceContext, but I don't know how to get it when using the TransferHandler method.
    I have other issues with the TransferHandler also, like trying to make DnD work consistently with Cut-And-Paste all in the same TransferHandler. Or, trying to deal with the fact that you can change a move-type DnD operation into a copy-type operation after you start dragging, but before you drop just by pressing the control-key. This sort of implies to me that the original createTransferable() should always make a copy, so that the only issue is whether to clean up in exportDone().

  • JTree cut and paste multiple child and ancestor nodes not function correct

    Hello i'm creating a filebrowser for multimedia files (SDK 1.22) such as .jpg .gif .au .wav. (using Swing, JTree, DefaultMutableTreeNode)
    The problem is I want to cut and paste single and multiple nodes (from current node til the last child "top-down") which partly functions:
    single nodes and multiple nodes with only one folder per hierarchy level;
    Not function:
    - multiple folders in the same level -> the former order gets lost
    - if there is a file (MMed. document) between folders (or after them) in the same level this file is put inside one of those
    I tried much easier functions to cope with this problem but every time I solve one the "steps" the next problem appears...
    The thing I don't want to do, is something like a LinkedList, Hashtable (to store the nodes)... because the MMed. filebrowser would need to much resources while browsing through a media library with (e.g.) thousands of files!
    If someone has any idea to solve this problem I would be very pleased!
    Thank you anyway by reading this ;)
    // part of the code, if you want more detailed info
    // @mail: [email protected]
    import java.util.Enumeration;
    import javax.swing.*;
    import javax.swing.tree.*;
    // var declaration
    static Enumeration en;
    static DefaultMutableTreeNode jTreeModel, lastCopiedNode, dmt, insert, insertParent, insertSameFolder;
    static String varCut;
    static int index= 0;
    static int counter = 0;
    /* cut function */
    if (actionCommand.equals ("cut"))
         // get the selected node (DefaultMutableTreeNode)
         lastCopiedNode = (DefaultMutableTreeNode)  selPath.getLastPathComponent ();
         // get the nodes in an Enumeration array (in top- down order)
         en = dmt.preorderEnumeration();
         // the way to make sure if it is a cut or a copied node
         varCut = "cut";
    /* paste function */
    if (actionCommand.equals ("paste"))
    // node is cut
    if (varCut == "cut")
    // is necessary for first time same folder case
    insertParent = dmt;
    // getting the nodes out of the array
    while(en.hasMoreElements())
         // cast the Object to DefaultMutableTreeNode
         // and get stored (next) node
         insert = (DefaultMutableTreeNode) en.nextElement();
    // check if the node is a catalogue when getRepresentation()
    // is a function of my node creating class (to know if it is
    // a folder or a file)
    if (insert.getRepresentation().equals("catalogue"))
         // check if a "folder" node is inserted
         if (index == 1)
              counter = 0;
              index = 0;
         System.out.println ("***index and counter reset***");
         // the node is in the same folder
         // check if the folder is in the same hierarchy level
         // -> in this case the insertParent has to remain
         if (insert.getLevel() == insertParent.getLevel())
              // this is necessary to get right parent folder
              insertSameFolder = (Knoten) insert.getParent();
              jTreeModel.insertNodeInto (insert, insertSameFolder, index);
    System.out.println (">>>sameFolderCASE- insert"+counter+"> " + String.valueOf(insert) +
              "\ninsertTest -> " + String.valueOf(insertTest)
              // set insertParent folder to the new createded one
              insertParent = insert;
              index ++;
         else // the node is a subfolder
              // insertNode
              jTreeModel.insertNodeInto (insert, insertParent, index);
              // set insertParent folder to the new createded one
              insertParent = insert;
    System.out.println (">>>subFolderCASE- insertParent"+counter+"> " + String.valueOf(insertParent) +
              "\ninsertParent -> " + String.valueOf(insertParent)
              index ++;
    else // the node is a file
         // insertNode
         jTreeModel.insertNodeInto (insert, insertParent, counter);
         System.out.println (">>>fileCASE insert "+counter+"> " + String.valueOf(insert) +
         "\ninsertParent -> " + String.valueOf(insertParent)
    counter ++;
    // reset index and counter for the next loop
    index = 0;
    counter = 0;
    // reset cut var
    varCut = null;
    // remove the node (automatically deletes subfolders and files)
    dmt.removeNodeFromParent (lastCopiedNode);
    // if node is a copied one
    if varCut == null)
         // insert copied node the same way as for cut one's
         // to make it possible to copy more than one node
    }

    You need to use a recursive copy method to do this. Here's a simple example of the copy. To do a cut you need to do a copy and then delete the source.
    import java.io.*;
    import javax.swing.*;
    import javax.swing.tree.*;
    import java.awt.BorderLayout;
    import java.awt.Container;
    import java.awt.event.*;
    import java.util.*;
    public class CopyTree extends JFrame
         Container cp;
         JTree cTree;
         JScrollPane spTree;
         DefaultTreeModel cModel;
         CNode cRoot;
         JMenuBar menuBar = new JMenuBar();
         JMenu editMenu = new JMenu("Edit");
         JMenuItem copyItem = new JMenuItem("Copy");
         JMenuItem pasteItem = new JMenuItem("Paste");
         TreePath [] sourcePaths;
         TreePath [] destPaths;
         // =====================================================================
         // constructors and public methods
         CopyTree()
              super("Copy Tree Example");
              addWindowListener(new WindowAdapter()
              {public void windowClosing(WindowEvent evt){System.exit(0);}});
              // edit menu
              copyItem.addActionListener(new ActionListener()
              {public void actionPerformed(ActionEvent e){mnuCopy();}});
              editMenu.add(copyItem);
              pasteItem.addActionListener(new ActionListener()
              {public void actionPerformed(ActionEvent e){mnuPaste();}});
              editMenu.add(pasteItem);
              menuBar.add(editMenu);
              setJMenuBar(menuBar);
              buildModel();
              cp = getContentPane();
              cTree = new JTree(cModel);
              spTree = new JScrollPane(cTree);
              cp.add(spTree, BorderLayout.CENTER);
              pack();
         static public void main(String [] args)
              new CopyTree().show();
         // =====================================================================
         // private methods - User Interface
         private void mnuCopy()
              sourcePaths = cTree.getSelectionPaths();
         private void mnuPaste()
              TreePath sp, dp;
              CNode sn,dn;
              int i;
              destPaths = cTree.getSelectionPaths();
              if(1 == destPaths.length)
                   dp = destPaths[0];
                   for(i=0; i< sourcePaths.length;i++)
                        sp = sourcePaths;
                        if(sp.isDescendant(dp) || dp.isDescendant(sp))
                             JOptionPane.showMessageDialog
                                  (null, "source and destinations overlap","Paste", JOptionPane.ERROR_MESSAGE);
                             return;
                   dn = (CNode)dp.getLastPathComponent(); // the node we will append our source to
                   for(i=0; i< sourcePaths.length;i++)
                        sn = (CNode)sourcePaths[i].getLastPathComponent();
                        copyNode(sn,dn);
              else
                   JOptionPane.showMessageDialog
                        (null, "multiple destinations not allowed","Paste", JOptionPane.ERROR_MESSAGE);
         // recursive copy method
         private void copyNode(CNode sn, CNode dn)
              int i;
              CNode scn = new CNode(sn);      // make a copy of the node
              // insert it into the model
              cModel.insertNodeInto(scn,dn,dn.getChildCount());
              // copy its children
              for(i = 0; i<sn.getChildCount();i++)
                   copyNode((CNode)sn.getChildAt(i),scn);
         // ===================================================================
         // private methods - just a sample tree
         private void buildModel()
              int k = 0;
              cRoot = new CNode("root");
              cModel = new DefaultTreeModel(cRoot);
              CNode n1a = new CNode("n1a");
              cModel.insertNodeInto(n1a,cRoot,k++);
              CNode n1b = new CNode("n1b");
              cModel.insertNodeInto(n1b,cRoot,k++);
              CNode n1c = new CNode("n1c");
              cModel.insertNodeInto(n1c,cRoot,k++);
              CNode n1d = new CNode("n1d");
              cModel.insertNodeInto(n1d,cRoot,k++);
              k = 0;
              CNode n1a1 = new CNode("n1a1");
              cModel.insertNodeInto(n1a1,n1a,k++);
              CNode n1a2 = new CNode("n1a2");
              cModel.insertNodeInto(n1a2,n1a,k++);
              CNode n1a3 = new CNode("n1a3");
              cModel.insertNodeInto(n1a3,n1a,k++);
              CNode n1a4 = new CNode("n1a4");
              cModel.insertNodeInto(n1a4,n1a,k++);
              k = 0;
              CNode n1c1 = new CNode("n1c1");
              cModel.insertNodeInto(n1c1,n1c,k++);
              CNode n1c2 = new CNode("n1c2");
              cModel.insertNodeInto(n1c2,n1c,k++);
         // simple tree node with copy constructor
         class CNode extends DefaultMutableTreeNode
              private String name = "";
              // default constructor
              CNode(){this("");}
              // new constructor
              CNode(String n){super(n);}
              // copy constructor
              CNode(CNode c)
                   super(c.getName());
              public String getName(){return (String)getUserObject();}
              public String toString(){return  getName();}

  • Changing JTree Expand And collapsed Icons

    Hi,
    can anyone tell me how to change the expanded and collpased icons on a JTree, i am using windows look and feel, and i don't know how to change the '+' and '-' icons, the other icons are changed using the DefaulTreeCellRenderer, but i haven't found a way to achieve my goal....
    thanks

    In the beginning of your main method you write :
    try {
         UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
         UIManager.put("Tree.collapsedIcon",new ImageIcon("plus.gif");
         UIManager.put("Tree.expandedIcon",new ImageIcon("minus.gif");
    catch (Exception exc) {
         System.err.println("Error loading L&F: " + exc);
    }And you change the name of the images with the wanted ones.
    Denis

  • JTree Listener and JMenu

    Help me on this:
    I want to create a JTree on which when I click right button of mouse a JMenu shows up and I choose what kind of the Item I want to add to selected node:
    Example :
    Main
    +
    |
    +-----> Chapter 1
    | |
    | +----------> Introduction
    |
    +------> Chapter 2
    When I select Chapter 1 in the Jtree I want to be able to add Introduction node to it throught JMenu
    Thanks Guys

    Okay the problem is I am adding the tree nodes dynamically andeach node will have it's own properties.
    Example:
    Step 1:
    For the first time my tree has no node, Then I want to add node to it. First I have to check whether if there is any node? If no then my JMenu should apear with the following items:
    -Add Course
    -Add Presentation
    We assume I have chosen Add Course, so a course node should be added to tree
    Step 2:
    Now we have a course node, if we select the course node and want to add a node to it we have to right click on the node, we have to decide wether if it is a course or a presentation node, then jmenu pops up according to what we have chosen: Let's assume we have chosen course, so the Jmen item should change to:
    -Add on-line course
    -Add off-line course
    but if it was Presentation node jmenu should apear like:
    -Add Confrenece
    -Add Marketing Presentation
    -Add .......
    Step 3:
    Let's assume we have chosen Add on-line course, first online course should be add to Course.
    Now we have three chices adding something to course again by selecting course node, or adding a multimedia node or an HTML node to this on-line course.
    As you can see every node will be dynamically added, them we have to see which one is selected to choose or change the jmenu according to the selected tree node.
    Please help me with that I am so confused. I am not an expert GUI programmer, I mostly programm on server side like APIs.

  • JTree nodeChanged() and nodeStructrueChanged()

    Hi,
    i wish to change in attributes of a child node in JTree userObject.
    Tree model having two methods to refresh the JTree. which is nodeChanged and nodeStructureChanged()
    which method i have to use? anybody can help me...?

    Here's what the documentation says:
    For nodeChanged:
    "Invoke this method after you've changed how node is to be represented in the tree."
    For nodeStructureChanged:
    "Invoke this method if you've totally changed the children of node and its childrens children."

  • JTree addSelectionPath and ClassCastExceptions

    Hi.
    I'm trying to build a tree view from a list of strings that represent relative path names (ie: Icons\a\image.dds)
    I have tokenized the path name based on the file separator and placed it into a String array which is used to create a new TreePath object, but when I try to add the tree path to the tree using tree.addSelectionPath(TreePath) it throws a ClassCastException: java.lang.String.
    Is this something I am doing wrong, or is this a problem with java? I have extensively searched the forum and have not found anything that relates to this.
    Thanks in advance.

    Same question on "model" and "view":
    JTable build on top of TableModel, I think the implenmentation of JTable constructor like this: invoke the methods of TableModel and get the rowCount and columnCount number, then according rowCount and columnCount number and "getValueAt()" method build a doulble "for" loop to create vector of vector, then according the vector of vector to build a table and draw the table, are these ideas correct?
    The question is every time when we modify the TableModel, we explicitly call "fireTableDataChanged()" method, this method will notify all of the listeners, where are these listeners? did these listeners recall JTable constructor to rebuild the table and draw? if yes, how does this happen? if not, where do we recall double "for" loop? it seems the simple and easys way to recall JTable constructor, but if we rebuild JTable object, how can we notify the JPanel to redraw? it seems lots of mystry on "model" and "view" for me.
    The big question is no body answer my questions, it is because my questions so simple, so easy or so stupid, I am new in Java, that's why I have these questions, I need Java professionals to help me!
    Thanks for all your help!

  • JEditorPane and JTree

    Hi,
    I have a tree that lists all objects and I want to do some kind of search feature. Results would be displayed in JEditorPane but I don't know anything about that. In JTree there is TreeSelectionListener (method valueChanged) and that has the functionality I need to have on JEditorPane but I don't know if this is possible?
    Any advices please?

    Hi,
    I have a tree that lists all objects and I want to do some kind of search feature. Results would be displayed in JEditorPane but I don't know anything about that. In JTree there is TreeSelectionListener (method valueChanged) and that has the functionality I need to have on JEditorPane but I don't know if this is possible?
    Any advices please?

  • Move node and its silings from one jtree to another

    Hi,
    I am trying to move JTree nodes and its siblings from one JTree to another. If anyone has the code, please post it on the website or mail to [email protected]
    Thanks
    Pavan

    Pavan,
    You may have to do a sanity check before adding it.
    Better run the program in a debugger and have a break point at the clipBoard.put() line. Else system.out.println() lines will kill enormouse programming time rather than using debugger.
    Also in following this thread, i found that you may have to be bit more thorough with the DefaultMutableTreeNode class first.
    Thanks,
    ananth
    Thomas,
    for (int p = 0; p < jtree.getSelectionCount(); p++) {
                   System.out.println(".3.......p= "+p);
    node =
    =
    (EuamDefaultMutableTreeNode)paths[p].getLastPathCompon
    nt();
                        clipBoard.put(node.toString(), node);
                   System.out.println(".4...........");
    Giving error at clipBoard.put()
    line....java.lang.NullPointerException
    ..Any idea why?
    Thanks.
    Pavan

Maybe you are looking for

  • Using a single Mac Remote with multiple devices

    Hi I have a Mac Remote which i use to control my MacBook Pro, however I also have a universal dock, and when my iPhone is connected to it, using the Mac Remote on my MacBook pro will also start affecting the iPhone as they are in close proximity of e

  • How do I store files from iPhoto onto a flash drive???

    My New Mac Book is full!!!!! I have 65gb of photos on it, and I cannot work out how to save them onto an external hard drive, I have tried to drag and drop, and that doesnt work.  Do i need to format the external drive for Mac?? If so, then how......

  • Posting period closing

    Hi Gurus, Can any one tell me is it neccessary to close the posting period every month. Can i have th posting period for my client open for one full year. which means open and close the posting period only once a year, rather than opening and closing

  • TS3999 Colors are randomly changing on my calendar. Is this a system issue?

    Color on my calendar changed without my changing it and then migrated to all the computers I am using ical on.  Is there something going on with ical as I lost a few postings on the calendar also after entering them.

  • Is there a way to upload/download photos anonymously?

    Is there a way to anonymously upload/download photos to the web without any sort of identification? For example, if I'm using something like TOR to browse, and I find an icon on a site or Google Images that I want to use as my avatar for a social net