I'm trying to implement a splitpane with scrollpanes on both sides. The left side should show a JTree that I'm attempting to implement but it's not working and I am unable to see the tree.
I'm not sure what I'm doing wrong. My code is something along the lines of:
public class SplitPane extends JFrame {
DefaultTreeModel treeModel;
JEditorPane editorPane = new JEditorPane();
DefaultMutableTreeNode Root;
JTree tree;
JScrollPane leftscrollPane;
JScrollPane rightscrollPane;
public SplitPane() {
setSize(600,400);
tree = new JTree(Root);
Root = new DefaultMutableTreeNode("");
setTree(); // I connect all the nodes here
treeModel = new DefaultTreeModel(Root);
tree = new JTree(Root);
tree.setRootVisible(false);
leftscrollPane = new JScrollPane(tree);
rightscrollPane = new JScrollPane(editorPane);
JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
splitPane.setLeftComponent(leftscrollPane);
splitPane.setRightComponent(rightscrollPane);
splitPane.setDividerLocation(160);
setVisible(true);
splitPane.setPreferredSize(new Dimension(600,400));
getContentPane().add(splitPane);
}
}
Then to initialize, I just do SplitPane newpane = new SplitPane();
I think I have all the nodes added properly because when I do
Enumeration e = Root.preorderEnumeration();
while(e.hasMoreElements()) {
System.out.println(e.nextElement());
}
I see all the nodes in order.
What am I doing wrong? I would really appreciate some help and feedback!