- All Implemented Interfaces:
ImageObserver,MenuContainer,Serializable,Accessible
JSplitPane is used to divide two (and only two)
Components. The two Components
are graphically divided based on the look and feel
implementation, and the two Components can then be
interactively resized by the user.
Information on using JSplitPane is in
How to Use Split Panes in
The Java Tutorial.
The two Components in a split pane can be aligned
left to right using
JSplitPane.HORIZONTAL_SPLIT, or top to bottom using
JSplitPane.VERTICAL_SPLIT.
The preferred way to change the size of the Components
is to invoke
setDividerLocation where location is either
the new x or y position, depending on the orientation of the
JSplitPane.
To resize the Components to their preferred sizes invoke
resetToPreferredSizes.
When the user is resizing the Components the minimum
size of the Components is used to determine the
maximum/minimum position the Components
can be set to. If the minimum size of the two
components is greater than the size of the split pane the divider
will not allow you to resize it. To alter the minimum size of a
JComponent, see JComponent.setMinimumSize(java.awt.Dimension).
When the user resizes the split pane the new space is distributed between
the two components based on the resizeWeight property.
A value of 0,
the default, indicates the right/bottom component gets all the space,
where as a value of 1 indicates the left/top component gets all the space.
Warning: Swing is not thread safe. For more information see Swing's Threading Policy.
Warning:
Serialized objects of this class will not be compatible with
future Swing releases. The current serialization support is
appropriate for short term storage or RMI between applications running
the same version of Swing. As of 1.4, support for long term storage
of all JavaBeans
has been added to the java.beans package.
Please see XMLEncoder.
- Since:
- 1.2
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected classThis class implements accessibility support for theJSplitPaneclass.Nested classes/interfaces declared in class javax.swing.JComponent
JComponent.AccessibleJComponentNested classes/interfaces declared in class java.awt.Container
Container.AccessibleAWTContainerNested classes/interfaces declared in class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringUsed to add aComponentbelow the otherComponent.static final StringBound property name for continuousLayout.protected booleanWhether or not the views are continuously redisplayed while resizing.static final StringUsed to add aComponentthat will represent the divider.static final StringBound property for the dividerLocation.static final StringBound property name for border.protected intSize of the divider.static final intHorizontal split indicates theComponents are split along the x axis.static final StringBound property for lastLocation.protected intPrevious location of the split pane.static final StringUsed to add aComponentto the left of the otherComponent.protected ComponentThe left or top component.static final StringBound property for oneTouchExpandable.protected booleanIs a little widget provided to quickly expand/collapse the split pane?protected intHow the views are split.static final StringBound property name for orientation (horizontal or vertical).static final StringBound property for weight.static final StringUsed to add aComponentto the right of the otherComponent.protected ComponentThe right or bottom component.static final StringUsed to add aComponentabove the otherComponent.static final intVertical split indicates theComponents are split along the y axis.Fields declared in class javax.swing.JComponent
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOWFields declared in class java.awt.Component
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENTFields declared in interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH -
Constructor Summary
ConstructorsConstructorDescriptionCreates a newJSplitPaneconfigured to arrange the child components side-by-side horizontally, using two buttons for the components.JSplitPane(int newOrientation) Creates a newJSplitPaneconfigured with the specified orientation.JSplitPane(int newOrientation, boolean newContinuousLayout) Creates a newJSplitPanewith the specified orientation and redrawing style.JSplitPane(int newOrientation, boolean newContinuousLayout, Component newLeftComponent, Component newRightComponent) Creates a newJSplitPanewith the specified orientation and redrawing style, and with the specified components.JSplitPane(int newOrientation, Component newLeftComponent, Component newRightComponent) Creates a newJSplitPanewith the specified orientation and the specified components. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidAdds the specified component to this split pane.Gets the AccessibleContext associated with this JSplitPane.Returns the component below, or to the right of the divider.intReturns the last value passed tosetDividerLocation.intReturns the size of the divider.intReturns the last location the divider was at.Returns the component to the left (or above) the divider.intReturns the maximum location of the divider from the look and feel implementation.intReturns the minimum location of the divider from the look and feel implementation.intReturns the orientation.doubleReturns the number that determines how extra space is distributed.Returns the component to the right (or below) the divider.Returns the component above, or to the left of the divider.getUI()Returns theSplitPaneUIthat is providing the current look and feel.Returns the name of the L&F class that renders this component.booleanGets thecontinuousLayoutproperty.booleanGets theoneTouchExpandableproperty.booleanReturns true, so that calls torevalidateon any descendant of thisJSplitPanewill cause a request to be queued that will validate theJSplitPaneand all its descendants.protected voidSubclassed to message the UI withfinishedPaintingChildrenafter super has been messaged, as well as painting the border.protected StringReturns a string representation of thisJSplitPane.voidremove(int index) Removes theComponentat the specified index.voidRemoves the child component,componentfrom the pane.voidRemoves all the child components from the split pane.voidLays out theJSplitPanelayout based on the preferred size of the children components.voidsetBottomComponent(Component comp) Sets the component below, or to the right of the divider.voidsetContinuousLayout(boolean newContinuousLayout) Sets the value of thecontinuousLayoutproperty, which must betruefor the child components to be continuously redisplayed and laid out during user intervention.voidsetDividerLocation(double proportionalLocation) Sets the divider location as a percentage of theJSplitPane's size.voidsetDividerLocation(int location) Sets the location of the divider.voidsetDividerSize(int newSize) Sets the size of the divider.voidsetLastDividerLocation(int newLastLocation) Sets the last location the divider was at tonewLastLocation.voidsetLeftComponent(Component comp) Sets the component to the left (or above) the divider.voidsetOneTouchExpandable(boolean newValue) Sets the value of theoneTouchExpandableproperty, which must betruefor theJSplitPaneto provide a UI widget on the divider to quickly expand/collapse the divider.voidsetOrientation(int orientation) Sets the orientation, or how the splitter is divided.voidsetResizeWeight(double value) Specifies how to distribute extra space when the size of the split pane changes.voidsetRightComponent(Component comp) Sets the component to the right (or below) the divider.voidsetTopComponent(Component comp) Sets the component above, or to the left of the divider.voidsetUI(SplitPaneUI ui) Sets the L&F object that renders this component.voidupdateUI()Notification from theUIManagerthat the L&F has changed.Methods declared in class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, paint, paintBorder, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, updateMethods declared in class java.awt.Container
add, add, add, add, add, addContainerListener, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate, validateTreeMethods declared in class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
-
Field Details
-
VERTICAL_SPLIT
public static final int VERTICAL_SPLITVertical split indicates theComponents are split along the y axis. For example the twoComponents will be split one on top of the other.- See Also:
-
HORIZONTAL_SPLIT
public static final int HORIZONTAL_SPLITHorizontal split indicates theComponents are split along the x axis. For example the twoComponents will be split one to the left of the other.- See Also:
-
LEFT
Used to add aComponentto the left of the otherComponent.- See Also:
-
RIGHT
Used to add aComponentto the right of the otherComponent.- See Also:
-
TOP
Used to add aComponentabove the otherComponent.- See Also:
-
BOTTOM
Used to add aComponentbelow the otherComponent.- See Also:
-
DIVIDER
Used to add aComponentthat will represent the divider.- See Also:
-
ORIENTATION_PROPERTY
Bound property name for orientation (horizontal or vertical).- See Also:
-
CONTINUOUS_LAYOUT_PROPERTY
Bound property name for continuousLayout.- See Also:
-
DIVIDER_SIZE_PROPERTY
Bound property name for border.- See Also:
-
ONE_TOUCH_EXPANDABLE_PROPERTY
Bound property for oneTouchExpandable.- See Also:
-
LAST_DIVIDER_LOCATION_PROPERTY
Bound property for lastLocation.- See Also:
-
DIVIDER_LOCATION_PROPERTY
Bound property for the dividerLocation.- Since:
- 1.3
- See Also:
-
RESIZE_WEIGHT_PROPERTY
Bound property for weight.- Since:
- 1.3
- See Also:
-
orientation
protected int orientationHow the views are split. -
continuousLayout
protected boolean continuousLayoutWhether or not the views are continuously redisplayed while resizing. -
leftComponent
The left or top component. -
rightComponent
The right or bottom component. -
dividerSize
protected int dividerSizeSize of the divider. -
oneTouchExpandable
protected boolean oneTouchExpandableIs a little widget provided to quickly expand/collapse the split pane? -
lastDividerLocation
protected int lastDividerLocationPrevious location of the split pane.
-
-
Constructor Details
-
JSplitPane
public JSplitPane()Creates a newJSplitPaneconfigured to arrange the child components side-by-side horizontally, using two buttons for the components. -
JSplitPane
Creates a newJSplitPaneconfigured with the specified orientation.- Parameters:
newOrientation-JSplitPane.HORIZONTAL_SPLITorJSplitPane.VERTICAL_SPLIT- Throws:
IllegalArgumentException- iforientationis not one of HORIZONTAL_SPLIT or VERTICAL_SPLIT.
-
JSplitPane
public JSplitPane(int newOrientation, boolean newContinuousLayout) Creates a newJSplitPanewith the specified orientation and redrawing style.- Parameters:
newOrientation-JSplitPane.HORIZONTAL_SPLITorJSplitPane.VERTICAL_SPLITnewContinuousLayout- a boolean, true for the components to redraw continuously as the divider changes position, false to wait until the divider position stops changing to redraw- Throws:
IllegalArgumentException- iforientationis not one of HORIZONTAL_SPLIT or VERTICAL_SPLIT
-
JSplitPane
Creates a newJSplitPanewith the specified orientation and the specified components.- Parameters:
newOrientation-JSplitPane.HORIZONTAL_SPLITorJSplitPane.VERTICAL_SPLITnewLeftComponent- theComponentthat will appear on the left of a horizontally-split pane, or at the top of a vertically-split panenewRightComponent- theComponentthat will appear on the right of a horizontally-split pane, or at the bottom of a vertically-split pane- Throws:
IllegalArgumentException- iforientationis not one of: HORIZONTAL_SPLIT or VERTICAL_SPLIT
-
JSplitPane
public JSplitPane(int newOrientation, boolean newContinuousLayout, Component newLeftComponent, Component newRightComponent) Creates a newJSplitPanewith the specified orientation and redrawing style, and with the specified components.- Parameters:
newOrientation-JSplitPane.HORIZONTAL_SPLITorJSplitPane.VERTICAL_SPLITnewContinuousLayout- a boolean, true for the components to redraw continuously as the divider changes position, false to wait until the divider position stops changing to redrawnewLeftComponent- theComponentthat will appear on the left of a horizontally-split pane, or at the top of a vertically-split panenewRightComponent- theComponentthat will appear on the right of a horizontally-split pane, or at the bottom of a vertically-split pane- Throws:
IllegalArgumentException- iforientationis not one of HORIZONTAL_SPLIT or VERTICAL_SPLIT
-
-
Method Details
-
setUI
Sets the L&F object that renders this component.- Parameters:
ui- theSplitPaneUIL&F object- See Also:
-
getUI
@BeanProperty(bound=false, expert=true, description="The L&F object that renders this component.") public SplitPaneUI getUI()Returns theSplitPaneUIthat is providing the current look and feel.- Overrides:
getUIin classJComponent- Returns:
- the
SplitPaneUIobject that renders this component
-
updateUI
public void updateUI()Notification from theUIManagerthat the L&F has changed. Replaces the current UI object with the latest version from theUIManager.- Overrides:
updateUIin classJComponent- See Also:
-
getUIClassID
@BeanProperty(bound=false, expert=true, description="A string that specifies the name of the L&F class.") public String getUIClassID()Returns the name of the L&F class that renders this component.- Overrides:
getUIClassIDin classJComponent- Returns:
- the string "SplitPaneUI"
- See Also:
-
setDividerSize
Sets the size of the divider. Divider sizesnewSize < 0are ignored.- Parameters:
newSize- an integer giving the size of the divider in pixels
-
getDividerSize
public int getDividerSize()Returns the size of the divider.- Returns:
- an integer giving the size of the divider in pixels
-
setLeftComponent
Sets the component to the left (or above) the divider.- Parameters:
comp- theComponentto display in that position
-
getLeftComponent
@BeanProperty(bound=false, preferred=true, description="The component to the left (or above) the divider.") public Component getLeftComponent()Returns the component to the left (or above) the divider.- Returns:
- the
Componentdisplayed in that position
-
setTopComponent
@BeanProperty(bound=false, description="The component above, or to the left of the divider.") public void setTopComponent(Component comp) Sets the component above, or to the left of the divider.- Parameters:
comp- theComponentto display in that position
-
getTopComponent
Returns the component above, or to the left of the divider.- Returns:
- the
Componentdisplayed in that position
-
setRightComponent
@BeanProperty(bound=false, preferred=true, description="The component to the right (or below) the divider.") public void setRightComponent(Component comp) Sets the component to the right (or below) the divider.- Parameters:
comp- theComponentto display in that position
-
getRightComponent
Returns the component to the right (or below) the divider.- Returns:
- the
Componentdisplayed in that position
-
setBottomComponent
@BeanProperty(bound=false, description="The component below, or to the right of the divider.") public void setBottomComponent(Component comp) Sets the component below, or to the right of the divider.- Parameters:
comp- theComponentto display in that position
-
getBottomComponent
Returns the component below, or to the right of the divider.- Returns:
- the
Componentdisplayed in that position
-
setOneTouchExpandable
@BeanProperty(description="UI widget on the divider to quickly expand/collapse the divider.") public void setOneTouchExpandable(boolean newValue) Sets the value of theoneTouchExpandableproperty, which must betruefor theJSplitPanet
-