Why the JTree does not show up? Here is my code:
initComponents();
JTree treeView;
DefaultMutableTreeNode top = new DefaultMutableTreeNode("myBooks");
DefaultMutableTreeNode category = new DefaultMutableTreeNode("Drama");
DefaultMutableTreeNode book1 = new DefaultMutableTreeNode("Macbeth");
DefaultMutableTreeNode book2 = new DefaultMutableTreeNode("Hamlet");
category.add(book1);
category.add(book2);
top.add(category);
treeView = new JTree(top);
JScrollPane pane = new JScrollPane(treeView);
mainPanel.add(pane);
To extend on Snicolas’ answer (1+ to him) you appear to be adding the JScrollPane to your mainPanel without regard for the layout manager used. I’m guessing that your GUI is using the GroupLayout, and if so, I suggest you use a layout manager that is more user friendly. Also, are you adding the pane JScrollPane after pack and setVisible(true) are called on the top-level window? If so you’ll need to revalidate and repaint the container that is receiving the new component.