// create the nodes and the leaves
operators[0] = new OpNode("+");
operators[1] = new OpNode("*");
operators[2] = new OpNode("-");
operators[3] = new OpNode("/");
operands[0] = new Integer(1);
operands[1] = new Integer(2);
operands[2] = new Integer(3);
operands[3] = new Integer(4);
operands[4] = new Integer(5);
// start our tree with a root of "+"
treeModel = new ExpressionTreeModel(operators[0]);
// build the tree from the root down
treeModel.insertNode(operators[0], operands[0], 0);
treeModel.insertNode(operators[0], operators[1], 1);
treeModel.insertNode(operators[1], operators[2], 0);
treeModel.insertNode(operators[1], operators[3], 1);
treeModel.insertNode(operators[2], operands[1], 0);
treeModel.insertNode(operators[2], operands[2], 1);
treeModel.insertNode(operators[3], operands[3], 0);
treeModel.insertNode(operators[3], operands[4], 1);
tree = new JTree(treeModel);
tree.setShowsRootHandles(true);
tree.collapseRow(0);
// Listen to our own expand/collapse events to keep the labels in sync
tree.addTreeExpansionListener(this);
getContentPane().add(tree, BorderLayout.CENTER);