e1025. adding a node to a jtree component.txt

来自「这里面包含了一百多个JAVA源文件」· 文本 代码 · 共 19 行

TXT
19
字号
// Create tree
    JTree tree = new JTree();
    DefaultTreeModel model = (DefaultTreeModel)tree.getModel();
    
    // Find node to which new node is to be added
    int startRow = 0;
    String prefix = "J";
    TreePath path = tree.getNextMatch(prefix, startRow, Position.Bias.Forward);
    MutableTreeNode node = (MutableTreeNode)path.getLastPathComponent();
    
    // Create new node
    MutableTreeNode newNode = new DefaultMutableTreeNode("green");
    
    // Insert new node as last child of node
    model.insertNodeInto(newNode, node, node.getChildCount());

 Related Examples 

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?