Java Reference
In-Depth Information
Although you can set the dividerLocation property with a double value, you can get only
an int , indicating its absolute position.
Tip With the system-provided look and feel classes, pressing the F8 key allows you to move the divider
with the keyboard keys such as Home, End, or the arrows. F8 isn't a modifier like Shift or Alt. Instead, pressing
F8 moves the focus to the divider so that it can be moved with keystrokes.
Resizing Components and Working with a One-Touch Expandable Divider
Limitations exist on the resizing of components within the JSplitPane . The JSplitPane honors
the minimum size of each contained component. If grabbing and moving the divider line will
cause a component to shrink to less than its minimum size, the scroll pane won't let the user
drag the divider past that minimum size.
Note You can always programmatically position the divider to be anywhere, even if it makes a component
smaller than its minimum size. However, this isn't a good idea because the component has a minimum size
for a good reason.
If the minimum dimensions of a component are too large for a JSplitPane , you need to
change the component's minimum size so that the divider can use some of that component's
space. For AWT components, changing the minimum size of a standard component requires
subclassing. With Swing components, you can simply call the setMinimumSize() method of
JComponent with a new Dimension . Nevertheless, minimum sizes are set for a reason. The compo-
nent probably won't look right if you explicitly shrink its minimum size.
A better approach is available for allowing one component to take up more space than
another: Set the oneTouchExpandable property of the JSplitPane to true . When this property is
true , an icon is added to the divider, allowing a user to completely collapse one of the two
components to give the other component the entire area. In the example in Figure 11-7, the
icon is a combination up-and-down arrow.
Figure 11-7 shows how this icon might appear (as rendered by the Ocean look and feel)
and illustrates what happens after selecting the up arrow on the divider to expand the lower
component to its fullest size. Clicking again on the icon on the divider returns the components
to their previous positions. Clicking on the divider somewhere other than on the icon will position
the divider in such a way that the collapsed component is at its preferred size.
 
Search WWH ::




Custom Search