summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAudrius Meskauskas <audriusa@Bioinformatics.org>2006-01-28 09:15:57 +0000
committerAudrius Meskauskas <audriusa@Bioinformatics.org>2006-01-28 09:15:57 +0000
commit88f18846592ffb88c4a13531fd5a7f037f69f009 (patch)
tree288333035132c0c2617a43eb8e5880703d06f78b
parent779d85b246a2c749904327b07dd55ce543450ef1 (diff)
downloadclasspath-88f18846592ffb88c4a13531fd5a7f037f69f009.tar.gz
2006-01-28 Audrius Meskauskas <AudriusA@Bioinformatics.org>
* gnu/classpath/examples/swing/Demo.java (mkTree): Make a larger tree. (addChildren): New method.
-rw-r--r--ChangeLog5
-rw-r--r--examples/gnu/classpath/examples/swing/Demo.java65
2 files changed, 40 insertions, 30 deletions
diff --git a/ChangeLog b/ChangeLog
index f6f9cb9b6..502b8b198 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2006-01-28 Audrius Meskauskas <AudriusA@Bioinformatics.org>
+
+ * gnu/classpath/examples/swing/Demo.java (mkTree): Make a larger tree.
+ (addChildren): New method.
+
2006-01-28 Raif S. Naffah <raif@swiftdsl.com.au>
* gnu/javax/crypto/jce/mac/MacAdapter.java (MacAdapter(IMac, Map)): New
diff --git a/examples/gnu/classpath/examples/swing/Demo.java b/examples/gnu/classpath/examples/swing/Demo.java
index 751aec0e8..705bf5b1f 100644
--- a/examples/gnu/classpath/examples/swing/Demo.java
+++ b/examples/gnu/classpath/examples/swing/Demo.java
@@ -947,37 +947,16 @@ public class Demo
return editorPane;
}
- private static JTree mkTree()
+ /**
+ * Create the tree.
+ *
+ * @return thr scroll pane, containing the tree.
+ */
+ private static JComponent mkTree()
{
DefaultMutableTreeNode root = new DefaultMutableTreeNode("Root node");
- DefaultMutableTreeNode child1 = new DefaultMutableTreeNode("Child node 1");
- DefaultMutableTreeNode child11 =
- new DefaultMutableTreeNode("Child node 1.1");
- DefaultMutableTreeNode child12 =
- new DefaultMutableTreeNode("Child node 1.2");
- DefaultMutableTreeNode child13 =
- new DefaultMutableTreeNode("Child node 1.3");
- DefaultMutableTreeNode child2 = new DefaultMutableTreeNode("Child node 2");
- DefaultMutableTreeNode child21 =
- new DefaultMutableTreeNode("Child node 2.1");
- DefaultMutableTreeNode child22 =
- new DefaultMutableTreeNode("Child node 2.2");
- DefaultMutableTreeNode child23 =
- new DefaultMutableTreeNode("Child node 2.3");
- DefaultMutableTreeNode child24 =
- new DefaultMutableTreeNode("Child node 2.4");
-
- DefaultMutableTreeNode child3 = new DefaultMutableTreeNode("Child node 3");
- root.add(child1);
- root.add(child2);
- root.add(child3);
- child1.add(child11);
- child1.add(child12);
- child1.add(child13);
- child2.add(child21);
- child2.add(child22);
- child2.add(child23);
- child2.add(child24);
+
+ addChildren("Node", root, 12);
JTree tree = new JTree(root);
tree.setLargeModel(true);
@@ -985,7 +964,33 @@ public class Demo
dtsm.setSelectionMode(DefaultTreeSelectionModel.SINGLE_TREE_SELECTION);
tree.setSelectionModel(dtsm);
- return tree;
+ // Make it editable.
+ tree.setEditable(true);
+
+ JComponent t = mkScrollPane(tree);
+ t.setPreferredSize(new Dimension(200,200));
+ return t;
+ }
+
+ /**
+ * Add the specified number of children to this parent node. For each
+ * child, the method is called recursively adding the nChildren-3 number of
+ * grandchildren.
+ *
+ * @param parent the parent node
+ * @param nChildren the number of children
+ */
+ private static void addChildren(String name, DefaultMutableTreeNode parent,
+ int nChildren)
+ {
+ for (int i = 0; i < nChildren; i++)
+ {
+ String child_name = parent+"."+i;
+ DefaultMutableTreeNode child = new DefaultMutableTreeNode
+ (child_name);
+ parent.add(child);
+ addChildren(child_name, child, nChildren-3);
+ }
}
/**