Java Reference
In-Depth Information
The orientation of a split pane is set using constants in the
JSplitPane class and can be set when the container is cre-
ated or explicitly later on. The constant HORIZONTAL_SPLIT
specifies that the components be displayed side by side. In
contrast, VERTICAL_SPLIT specifies that the components be
displayed one on top of the other.
The location of the divider bar determines how much visible area is devoted
to each component in the split pane. The divider bar can be dragged across the
container area using the mouse. As it moves, the visible space is increased for one
component and decreased for the other. The total space allotted for both compo-
nents changes only if the size of the entire split pane changes.
A JSplitPane respects the minimum size set for the components it displays.
Therefore, the divider bar may not allow a section to be reduced in size beyond
a particular point. To adjust this aspect, the minimum sizes of the components
displayed can be changed.
The divider bar of a JSplitPane object can be set so that it can be expanded,
one direction or the other, with one click of the mouse. By default, the divider bar
does not have this feature and can be moved only by dragging it. If this feature
is turned on, the divider bar appears with two small arrows pointing in opposite
directions. Clicking either of these arrows causes the divider bar to move fully
in that direction, maximizing the space allotted to one of the components. This
feature is set using the setOneTouchExpandable method, which takes a boolean
parameter. The size of the divider bar and the initial location of the divider bar
can be set explicitly as well.
Another feature that can be set on a JSplitPane is whether or not the components
are continuously adjusted and repainted as the divider bar is being moved. If this
feature is not set, the components' layout managers will be consulted only after the
divider bar stops moving. This feature is off by default and can be turned on when
the JSplitPane object is created or by using the setContinuousLayout method.
Split panes can be nested by putting a split pane into one or both sides of
another split pane. For example, we could divide a container into three sections
by putting a split pane into the top component of another split pane. There would
then be two divider bars, one that separates the total area into two main sections
and another that separates one of those sections into two others. How much vis-
ible area is shown in each would depend on where the divider bars are placed.
The program shown in Listing 11.14 presents a list of image file names to the
user. When one of the file names is selected, the corresponding image is displayed
in the right side of the split pane.
The split pane is created in the main method and added to the frame to be
displayed. The split pane is oriented, using the HORIZONTAL_SPLIT constant, such
KEY CONCEPT
A split pane displays two compo-
nents side by side or one on top of
the other.
Search WWH ::




Custom Search