JTreeの内容をアップデートする JTreeの内容をアップデートするには、TreeModelのreload()を使用します。
reloadと同時にツリーの表示も更新されます。
その後、scrollPathToVisible()で新しいノードを表示します。
// Initialize
DefaultMutableTreeNode root = new DefaultMutableTreeNode("Root");
JTree tree = new JTree(root);
// Change
DefaultMutableTreeNode node = new DefaultMutableTreeNode("New");
root.add(node);
// Update
TreeModel treeModel = tree.getModel();
treeModel.reload();
tree.scrollPathToVisible(new TreePath(node.getPath()));
tree.setSelectionPath(new TreePath(categoryNode.getPath()));
目次に戻る
| Copyright(c) 2008 WoodenSoldier Software |
|