How to create a JScrollPane with a JTree

The first thing we want to add to our JSplitPane is a JTree to be found on the left side of the split pane. But a JTree alone doesn't make much sense because it has no viewport of its own that scrolls when the tree expands. Therefore follow these steps:

  • In the Tree Panel of the GUI builder select the JSplitPane you have created and add a JScrollPane by pressing the new JScrollPane button on the right toolbar.
  • In the Tree Panel of the GUI builder select the JScrollPane you have just created and add a JTree by pressing the new JTree button on the right toolbar.
  • Activate the Items check box within the JTree editor.

Select your frame and check it out and you will see the tree you've created from the string resources

Root:leaf_1|leaf_2|leaf_3.

If you want to have an XML structure as a model, change to the editor of the tree Component, select XMLFile from the Items combo box, press the resource dialog button (furthest right) and search for the MyJFrame.xml file we have created in our examples above.