Brought to you by EarthWeb
ITKnowledge Logo Login Graphic Click Here!
Click Here!
ITKnowledge
Search this book:
 
Search the site:
 
EXPERT SEARCH ----- nav

EarthWeb Direct

EarthWeb Direct

EarthWeb sites: other sites

Previous Table of Contents Next


JSplitPane Divider Configuration

In the JSplitPaneTest application, the default configuration for the divider was used. The size of the slider is look-and-feel dependent. The divider in the Windows look-and-feel is three pixels wide, in the Java look-and-feel it is eight pixels wide, and in the motif look-and-feel it is a whopping 18 pixels wide. If the default value of the divider is not appropriate for your application, you can specify it by using the setDividerSize method. The current size of the divider can be queried with the getDividerSize method. As shown in Table 16.1, the divider’s size is a bound property of the JSplitPane class.

The divider can be configured with a region that allows either panel to be collapsed by clicking the mouse over the control. Once collapsed, the panel can be restored to its original size by clicking on the other arrow in the one-touch control. The setOneTouchExpandable method activates or deactivates this control. Its current state can be queried with the isOneTouchExpandable method. The oneTouchExpandable property is a bound property of the JSplitPane class. Add the following line of code to the JSplitPaneTest constructor to enable one-touch expansion mode in the split pane:

splitPane.setOneTouchExpandable( true );

The resulting window is shown in Figure 16.3. The one-touch region is the area with the two black arrows at the top of the divider. Clicking the top arrow collapses the left region, and clicking the bottom arrow collapses the right region. Figure 16.4 shows the window after the top arrow has been clicked to collapse the region containing the table. The bottom arrow would be clicked to restore the window to its original layout.


Figure 16.3  A one-touch control added to JSplitPane


Figure 16.4  …and a collapsed JSplitPane.


Note:  
When you’re using the one-touch control, the default divider size of the Windows and Java look-and-feels makes the control difficult to click. This is more of a factor with the Windows look-and-feel. Increasing the size of the divider to 10 pixels or more gives the controls more space, allowing them to be clicked easier.

The location of the divider can be specified by the application using the setDividerLocation method. The integer parameter to this method is look-and-feel dependent. However, the current look-and-feel implementations interpret this parameter as a pixel count. It is the x location for a horizontally aligned split pane and the y location for a vertically aligned split pane. The current value of the divider can be queried with the getDividerLocation method.

The previous divider location is a bound property of the split pane. When the continuous layout property is false, a property change listener will be notified of the last divider location after a drag operation is complete. The name of the property in the PropertyChangeEvent is the String defined by the LAST_DIVIDER_LOCATION_PROPERTY constant in the JSplitPane class. If the continuous layout property is true, the listener will receive a stream of change events as the user drags the divider. The getDividerLocation method can be used to query the current location of the divider in the propertyChange method. The getLastDividerLocation method can be called to query the divider’s previous location. This value is also delivered to listeners by the PropertyChange event.

There is a setLastDividerLocation method that is used by the look-and-feel implementations to set this property and initiate the PropertyChangeEvent being fired. This method is rarely used by user applications.

There is also a variant of the setDividerLocation method that takes a double as its parameter. The parameter must be between 0.0 and 1.0. It is interpreted as the percentage of the split pane given to the top or left component, depending on the orientation. The remainder of the area is given to the other component. Calling this method will also cause a LAST_DIVIDER_LOCATION_PROPERTY PropertyChangeEvent to be sent to any PropertyChangeListeners listeners registered on the split pane.

The minimum and maximum placement locations for the divider can be queried with the getMinimumDividerLocation and getMaximumDividerLocation methods. These values cannot be set directly by the application. Instead, they are determined by the preferences of the components managed by the split pane. Component sizing is discussed in the next section.


Previous Table of Contents Next
HomeAbout UsSearchSubscribeAdvertising InfoContact UsFAQs
Use of this site is subject to certain Terms & Conditions.
Copyright (c) 1996-1999 EarthWeb Inc. All rights reserved. Reproduction in whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement.