updating JTree in java GUI

前端 未结 3 871
不知归路
不知归路 2021-02-14 08:21

I used a JTree in my GUI and added it to a JFrame. When I want to update it and change it\'s nodes in another part of my program (while program is running, as an action performe

3条回答
  •  悲哀的现实
    2021-02-14 08:25

    In addition to the insertNodeInto suggestion you can also use:

    DefaultTreeModel model = (DefaultTreeModel)tree.getModel();
    DefaultMutableTreeNode root = (DefaultMutableTreeNode)model.getRoot();
    root.add(new DefaultMutableTreeNode("another_child"));
    model.reload(root);
    

提交回复
热议问题