| |
14. 67. 14. JTree root cannot be removed with removeNodeFromParent(), use DefaultTreeModel.setRoot() to remove the root |
|
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTree;
import javax.swing.tree.DefaultTreeModel;
public class TreeRootRemove {
public static void main(String[] argv) {
JTree tree = new JTree();
DefaultTreeModel model = (DefaultTreeModel) tree.getModel();
model.setRoot(null);
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(new JScrollPane(tree));
frame.setSize(380, 320);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
}
|
|
|