如何限制jtree扩展?

时间:2014-03-18 02:32:51

标签: java jtree

我希望我的jtree有root parentchild

用户不应该添加孩子

我该怎么做?

public DefaultMutableTreeNode addObject(Object child) {
        DefaultMutableTreeNode parentNode = null;
        TreePath parentPath = tree.getSelectionPath();
            // i need to add some code here to restrict adding if element is a child 
            // if ( the selected element is a child ) then the following code shall not work 
        if (parentPath == null) {
            parentNode = rootNode;
        } else {
            parentNode = (DefaultMutableTreeNode) (parentPath
                    .getLastPathComponent());
        }
        return addObject(parentNode, child, true); 
    }

0 个答案:

没有答案