Subpages: 1. Split Panes: JSplitPane
2. Basic split pane example
3. Gas model simulation using a split pane
Chapter 8. Split Panes
In this chapter:
- JSplitPane
- Basic split pane example
- Gas model simulation using a split pane
8.1 JSplitPane
class javax.swing.JSplitPane
Split panes allow the user to dynamically change the size of two or more components displayed side-by-side (within a window or another panel). Special dividers can be dragged with the mouse to increase space for one component and decrease the display space for another. Note that the total display area does not change. This gives applications a more modern and sophisticated view. A familiar example is the combination of a tree and a table separated by a horizontal divider (e.g. file explorer-like applications). The Swing framework for split panes consists only of JSplitPane.
JSplitPane can hold two components separated by a horizontal or vertical divider. The components on either side of a JSplitPane can be added either in one of the constructors, or with the proper setXXComponent() methods (where XX is substituted by Left, Right, Top, or Bottom). We can also set the orientation at run-time using its setOrientation() method.
The divider between the side components represents the only visible part of JSplitPane. It's size can be managed with the setDividerSize() method, and its position by the two overloaded setDividerLocation() methods (which take an absolute location in pixels or proportional location as a double). The divider location methods have no affect until JSplitPane is displayed. JSplitPane also maintains a oneTouchExpandable property which, when true, places two small arows inside the divider that will move the divider to its extremities when clicked.
UI Guideline : Resizable Panelled Display
Split pane becomes really useful when your design has panelled the display for ease of use but you (as designer) have no control over the actual window size. The Netscape e-mail reader is a good example of this. A split pane is introduced to let the user vary the size of the message header panel against the size of the message text panel.
An interesting feature of the JSplitPane component is that you can specify whether or not to repaint side components during the divider's motion using the setContinuousLayout() method. If you can repaint components fast enough, resizing will have a more natural view with this setting. Otherwise, this flag should be set to false, in which case side components will be repainted only when the divider's new location is chosen. In this latter case, a divider line will be shown as the divider location is dragged to illustrate the new position.
JSplitPane will not size any of its constituent components smaller than their minimum sizes. If the minimum size of each component is larger than the size of the splitpane the divider will be effectively disabled (unmovable). Also note that we can call its resetToPreferredSize() method to resize its children to their preferred sizes, if possible.
UI Guideline : Use Split Pane in conjunction with Scroll Pane
Its important to use a Scroll Pane on the panels which are being split with the Split Pane. The scroll bar will then invoke automatically as required when data is obscured as the split pane is dragged back and forth. The introduction of the scroll pane gives the viewer a clear indication that there is some hidden data. They can then choose to scroll with the scroll bar or uncover the data using the split pane.


RSS feed Java FAQ News