diff options
author | Audrius Meskauskas <audriusa@Bioinformatics.org> | 2006-04-26 09:03:06 +0000 |
---|---|---|
committer | Audrius Meskauskas <audriusa@Bioinformatics.org> | 2006-04-26 09:03:06 +0000 |
commit | e94ee062e444b58b9b1b38b9a825b9d0249f12ea (patch) | |
tree | 9bb7f5e714b5bd96de087b4125c7b662ecb841af /examples | |
parent | a55fc3fbef07b23445aa53323e0067d79477e052 (diff) | |
download | classpath-e94ee062e444b58b9b1b38b9a825b9d0249f12ea.tar.gz |
2006-04-26 Audrius Meskauskas <AudriusA@Bioinformatics.org>
* examples/gnu/classpath/examples/swing/TreeDemo.java
(createContent): Call DefaultTreeModel.reload(), not the
tree.repaint(). Expand the parent of the added node.
* javax/swing/JTree.java (constructor): Do not call
UpdateUI (and documented why). (treeDidChange):
Added comment, excluding the misinterpretation of this method.
* javax/swing/plaf/basic/BasicTreeUI.java (componentListener,
focusListener, keyListener, mouseListener, propertyListener,
selectionModelPropertyChangeListener, treeModelListener,
treeSelectionListener): Made package private.
(PropertyChangeHandler): If the model changes, install the
listener on it. (installUI): Assign treeModel.
* javax/swing/tree/DefaultMutableTreeNode.java (add): Added
comment, excluding misinterpretation.
* javax/swing/tree/DefaultTreeModel.java (reload): Implemented.
(reload(TreeNode)): Implemented.
Diffstat (limited to 'examples')
-rw-r--r-- | examples/gnu/classpath/examples/swing/TreeDemo.java | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/examples/gnu/classpath/examples/swing/TreeDemo.java b/examples/gnu/classpath/examples/swing/TreeDemo.java index 1762f065d..a54585940 100644 --- a/examples/gnu/classpath/examples/swing/TreeDemo.java +++ b/examples/gnu/classpath/examples/swing/TreeDemo.java @@ -53,6 +53,7 @@ import javax.swing.JScrollPane; import javax.swing.JTree; import javax.swing.SwingUtilities; import javax.swing.tree.DefaultMutableTreeNode; +import javax.swing.tree.DefaultTreeModel; import javax.swing.tree.DefaultTreeSelectionModel; import javax.swing.tree.TreePath; import javax.swing.tree.TreeSelectionModel; @@ -133,9 +134,10 @@ public class TreeDemo final JTree tree = new JTree(root); tree.setLargeModel(true); tree.setEditable(true); - DefaultTreeSelectionModel dtsm = new DefaultTreeSelectionModel(); - dtsm.setSelectionMode(DefaultTreeSelectionModel.SINGLE_TREE_SELECTION); - tree.setSelectionModel(dtsm); + final DefaultTreeSelectionModel selModel = new DefaultTreeSelectionModel(); + selModel.setSelectionMode( + DefaultTreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION); + tree.setSelectionModel(selModel); // buttons to add and delete JButton add = new JButton("add element"); @@ -151,7 +153,16 @@ public class TreeDemo DefaultMutableTreeNode n = (DefaultMutableTreeNode) p. getLastPathComponent(); n.add(new DefaultMutableTreeNode("New Element")); - tree.repaint(); + + // The expansion state of the parent node does not change + // by default. We will expand it manually, to ensure that the + // added node is immediately visible. + tree.expandPath(p); + + // Refresh the tree (.repaint would be not enough both in + // Classpath and Sun implementations). + DefaultTreeModel model = (DefaultTreeModel) tree.getModel(); + model.reload(n); break; } } @@ -163,12 +174,11 @@ public class TreeDemo { public void actionPerformed(ActionEvent e) { - TreeSelectionModel model = tree.getSelectionModel(); if (cbSingle.isSelected()) - model.setSelectionMode( + selModel.setSelectionMode( DefaultTreeSelectionModel.SINGLE_TREE_SELECTION); else - model.setSelectionMode( + selModel.setSelectionMode( DefaultTreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION); } }); |