JSplitPane and its components

The visual editor has special behavior to make it easy to work with a Swing JSplitPane container.

You can use the class javax.swing.JSplitPane to create two components with a split bar between them. At run time, a user can drag the split bar to adjust the space on the screen.

In the visual editor, the two child components are shown beneath the JSplitPane on the Java Beans view. When you drop a new component onto a JSplitPane in the Java Beans view or the Design view, the visual editor will try to place the component in the left pane if there is no existing child. If there is already a component in the left pane, the component that you are dropping will be added to the right pane. If both panes in the JSplitPane are already occupied, the visual editor will not allow you to drop the component.

Whether the visual editor for Java shows the left and right component as children depends on the value of its orientation property. If this property is set to VERTICAL_SPLIT then the bottom and top component are shown instead.

The method generated for each of the split pane children is to set one of its properties using a set method. For example:

ivjJSplitPane.setTopComponent(getIvjJButton());

In addition to setting a component using a set method, it can be added using a constraint of "top", "bottom" "left" or "right". For example:

ivjJSplitPane.addComponent(getIvjJButton(),"top");

Note: Although the visual editor generates code that uses the set method, the Design view will also recognize the add(Component,Object) method with a valid constraint.

When you drop components onto a JSplitPane, if the divider location is not explicitly set, the divider location will change according to the preferred size of the left or top component. Then it will fill the opposite side with the remaining component if one is set. For example, if you drop a JPanel into a JSplitPane with no components, it will be assigned by default to the left side. The divider location will move to the far left in the split pane because the preferredSize for a JPanel is very small. If you then drop components onto the JPanel, which is using a FlowLayout, the split pane will resize according to the preferred size of the JPanel, which has now changed because of the preferred sizes of the components that were added to it.

The visual editor will render JLayeredPane indexes in a single layer. In the case of multilayer and indexes, the visual editor may not show the components in the correct order.

 

Parent topic

Working with Swing in the visual editor