ImageObserver
, MenuContainer
, Serializable
, Accessible
@JavaBean(defaultProperty="UI") public class JSplitPane extends JComponent implements Accessible
JSplitPane
is used to divide two (and only two) Component
s. The two Component
s are graphically divided based on the look and feel implementation, and the two Component
s 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 Component
s 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 Component
s is to invoke setDividerLocation
where location
is either the new x or y position, depending on the orientation of the JSplitPane
.
To resize the Component
s to their preferred sizes invoke resetToPreferredSizes
.
When the user is resizing the Component
s the minimum size of the Components
is used to determine the maximum/minimum position the Component
s 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
.
Modifier and Type | Class | Description |
---|---|---|
protected class |
JSplitPane.AccessibleJSplitPane |
This class implements accessibility support for the JSplitPane class. |
JComponent.AccessibleJComponent
Container.AccessibleAWTContainer
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
Modifier and Type | Field | Description |
---|---|---|
static final String |
BOTTOM |
Used to add a Component below the other Component . |
static final String |
CONTINUOUS_LAYOUT_PROPERTY |
Bound property name for continuousLayout. |
protected boolean |
continuousLayout |
Whether or not the views are continuously redisplayed while resizing. |
static final String |
DIVIDER |
Used to add a Component that will represent the divider. |
static final String |
DIVIDER_LOCATION_PROPERTY |
Bound property for the dividerLocation. |
static final String |
DIVIDER_SIZE_PROPERTY |
Bound property name for border. |
protected int |
dividerSize |
Size of the divider. |
static final int |
HORIZONTAL_SPLIT |
Horizontal split indicates the Component s are split along the x axis. |
static final String |
LAST_DIVIDER_LOCATION_PROPERTY |
Bound property for lastLocation. |
protected int |
lastDividerLocation |
Previous location of the split pane. |
static final String |
LEFT |
Used to add a Component to the left of the other Component . |
protected Component |
leftComponent |
The left or top component. |
static final String |
ONE_TOUCH_EXPANDABLE_PROPERTY |
Bound property for oneTouchExpandable. |
protected boolean |
oneTouchExpandable |
Is a little widget provided to quickly expand/collapse the split pane? |
protected int |
orientation |
How the views are split. |
static final String |
ORIENTATION_PROPERTY |
Bound property name for orientation (horizontal or vertical). |
static final String |
RESIZE_WEIGHT_PROPERTY |
Bound property for weight. |
static final String |
RIGHT |
Used to add a Component to the right of the other Component . |
protected Component |
rightComponent |
The right or bottom component. |
static final String |
TOP |
Used to add a Component above the other Component . |
static final int |
VERTICAL_SPLIT |
Vertical split indicates the Component s are split along the y axis. |
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
Constructor | Description |
---|---|
JSplitPane() |
Creates a new JSplitPane configured to arrange the child components side-by-side horizontally, using two buttons for the components. |
JSplitPane |
Creates a new JSplitPane configured with the specified orientation. |
JSplitPane |
Creates a new JSplitPane with the specified orientation and redrawing style. |
JSplitPane |
Creates a new JSplitPane with the specified orientation and redrawing style, and with the specified components. |
JSplitPane |
Creates a new JSplitPane with the specified orientation and the specified components. |
Modifier and Type | Method | Description |
---|---|---|
protected void |
addImpl |
Adds the specified component to this split pane. |
AccessibleContext |
getAccessibleContext() |
Gets the AccessibleContext associated with this JSplitPane. |
Component |
getBottomComponent() |
Returns the component below, or to the right of the divider. |
int |
getDividerLocation() |
Returns the last value passed to setDividerLocation . |
int |
getDividerSize() |
Returns the size of the divider. |
int |
getLastDividerLocation() |
Returns the last location the divider was at. |
Component |
getLeftComponent() |
Returns the component to the left (or above) the divider. |
int |
getMaximumDividerLocation() |
Returns the maximum location of the divider from the look and feel implementation. |
int |
getMinimumDividerLocation() |
Returns the minimum location of the divider from the look and feel implementation. |
int |
getOrientation() |
Returns the orientation. |
double |
getResizeWeight() |
Returns the number that determines how extra space is distributed. |
Component |
getRightComponent() |
Returns the component to the right (or below) the divider. |
Component |
getTopComponent() |
Returns the component above, or to the left of the divider. |
SplitPaneUI |
getUI() |
Returns the SplitPaneUI that is providing the current look and feel. |
String |
getUIClassID() |
Returns the name of the L&F class that renders this component. |
boolean |
isContinuousLayout() |
Gets the continuousLayout property. |
boolean |
isOneTouchExpandable() |
Gets the oneTouchExpandable property. |
boolean |
isValidateRoot() |
Returns true, so that calls to revalidate on any descendant of this JSplitPane will cause a request to be queued that will validate the JSplitPane and all its descendants. |
protected void |
paintChildren |
Subclassed to message the UI with finishedPaintingChildren after super has been messaged, as well as painting the border. |
protected String |
paramString() |
Returns a string representation of this JSplitPane . |
void |
remove |
Removes the Component at the specified index. |
void |
remove |
Removes the child component, component from the pane. |
void |
removeAll() |
Removes all the child components from the split pane. |
void |
resetToPreferredSizes() |
Lays out the JSplitPane layout based on the preferred size of the children components. |
void |
setBottomComponent |
Sets the component below, or to the right of the divider. |
void |
setContinuousLayout |
Sets the value of the continuousLayout property, which must be true for the child components to be continuously redisplayed and laid out during user intervention. |
void |
setDividerLocation |
Sets the divider location as a percentage of the JSplitPane 's size. |
void |
setDividerLocation |
Sets the location of the divider. |
void |
setDividerSize |
Sets the size of the divider. |
void |
setLastDividerLocation |
Sets the last location the divider was at to newLastLocation . |
void |
setLeftComponent |
Sets the component to the left (or above) the divider. |
void |
setOneTouchExpandable |
Sets the value of the oneTouchExpandable property, which must be true for the JSplitPane to provide a UI widget on the divider to quickly expand/collapse the divider. |
void |
setOrientation |
Sets the orientation, or how the splitter is divided. |
void |
setResizeWeight |
Specifies how to distribute extra space when the size of the split pane changes. |
void |
setRightComponent |
Sets the component to the right (or below) the divider. |
void |
setTopComponent |
Sets the component above, or to the left of the divider. |
void |
setUI |
Sets the L&F object that renders this component. |
void |
updateUI() |
Notification from the UIManager that the L&F has changed. |
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, update
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, validateTree
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
public static final int VERTICAL_SPLIT
Component
s are split along the y axis. For example the two Component
s will be split one on top of the other.public static final int HORIZONTAL_SPLIT
Component
s are split along the x axis. For example the two Component
s will be split one to the left of the other.public static final String LEFT
Component
to the left of the other Component
.public static final String RIGHT
Component
to the right of the other Component
.public static final String TOP
Component
above the other Component
.public static final String BOTTOM
Component
below the other Component
.public static final String DIVIDER
Component
that will represent the divider.public static final String ORIENTATION_PROPERTY
public static final String CONTINUOUS_LAYOUT_PROPERTY
public static final String DIVIDER_SIZE_PROPERTY
public static final String ONE_TOUCH_EXPANDABLE_PROPERTY
public static final String LAST_DIVIDER_LOCATION_PROPERTY
public static final String DIVIDER_LOCATION_PROPERTY
public static final String RESIZE_WEIGHT_PROPERTY
protected int orientation
protected boolean continuousLayout
protected Component leftComponent
protected Component rightComponent
protected int dividerSize
protected boolean oneTouchExpandable
protected int lastDividerLocation
public JSplitPane()
JSplitPane
configured to arrange the child components side-by-side horizontally, using two buttons for the components.@ConstructorProperties("orientation") public JSplitPane(int newOrientation)
JSplitPane
configured with the specified orientation.newOrientation
- JSplitPane.HORIZONTAL_SPLIT
or JSplitPane.VERTICAL_SPLIT
IllegalArgumentException
- if orientation
is not one of HORIZONTAL_SPLIT or VERTICAL_SPLIT.public JSplitPane(int newOrientation, boolean newContinuousLayout)
JSplitPane
with the specified orientation and redrawing style.newOrientation
- JSplitPane.HORIZONTAL_SPLIT
or JSplitPane.VERTICAL_SPLIT
newContinuousLayout
- a boolean, true for the components to redraw continuously as the divider changes position, false to wait until the divider position stops changing to redrawIllegalArgumentException
- if orientation
is not one of HORIZONTAL_SPLIT or VERTICAL_SPLITpublic JSplitPane(int newOrientation, Component newLeftComponent, Component newRightComponent)
JSplitPane
with the specified orientation and the specified components.newOrientation
- JSplitPane.HORIZONTAL_SPLIT
or JSplitPane.VERTICAL_SPLIT
newLeftComponent
- the Component
that will appear on the left of a horizontally-split pane, or at the top of a vertically-split panenewRightComponent
- the Component
that will appear on the right of a horizontally-split pane, or at the bottom of a vertically-split paneIllegalArgumentException
- if orientation
is not one of: HORIZONTAL_SPLIT or VERTICAL_SPLITpublic JSplitPane(int newOrientation, boolean newContinuousLayout, Component newLeftComponent, Component newRightComponent)
JSplitPane
with the specified orientation and redrawing style, and with the specified components.newOrientation
- JSplitPane.HORIZONTAL_SPLIT
or JSplitPane.VERTICAL_SPLIT
newContinuousLayout
- 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
- the Component
that will appear on the left of a horizontally-split pane, or at the top of a vertically-split panenewRightComponent
- the Component
that will appear on the right of a horizontally-split pane, or at the bottom of a vertically-split paneIllegalArgumentException
- if orientation
is not one of HORIZONTAL_SPLIT or VERTICAL_SPLITpublic void setUI(SplitPaneUI ui)
ui
- the SplitPaneUI
L&F object@BeanProperty(bound=false, expert=true, description="The L&F object that renders this component.") public SplitPaneUI getUI()
SplitPaneUI
that is providing the current look and feel.getUI
in class JComponent
SplitPaneUI
object that renders this componentpublic void updateUI()
UIManager
that the L&F has changed. Replaces the current UI object with the latest version from the UIManager
.updateUI
in class JComponent
@BeanProperty(bound=false, expert=true, description="A string that specifies the name of the L&F class.") public String getUIClassID()
getUIClassID
in class JComponent
@BeanProperty(description="The size of the divider.") public void setDividerSize(int newSize)
newSize < 0
are ignored.newSize
- an integer giving the size of the divider in pixelspublic int getDividerSize()
public void setLeftComponent(Component comp)
comp
- the Component
to display in that position@BeanProperty(bound=false, preferred=true, description="The component to the left (or above) the divider.") public Component getLeftComponent()
Component
displayed in that position@BeanProperty(bound=false, description="The component above, or to the left of the divider.") public void setTopComponent(Component comp)
comp
- the Component
to display in that positionpublic Component getTopComponent()
Component
displayed in that position@BeanProperty(bound=false, preferred=true, description="The component to the right (or below) the divider.") public void setRightComponent(Component comp)
comp
- the Component
to display in that positionpublic Component getRightComponent()
Component
displayed in that position@BeanProperty(bound=false, description="The component below, or to the right of the divider.") public void setBottomComponent(Component comp)
comp
- the Component
to display in that positionpublic Component getBottomComponent()
Component
displayed in that position@BeanProperty(description="UI widget on the divider to quickly expand/collapse the divider.") public void setOneTouchExpandable(boolean newValue)
oneTouchExpandable
property, which must be true
for the JSplitPane
to provide a UI widget on the divider to quickly expand/collapse the divider. The default value of this property is false
. Some look and feels might not support one-touch expanding; they will ignore this property.newValue
- true
to specify that the split pane should provide a collapse/expand widgetpublic boolean isOneTouchExpandable()
oneTouchExpandable
property.oneTouchExpandable
property@BeanProperty(description="The last location the divider was at.") public void setLastDividerLocation(int newLastLocation)
newLastLocation
.newLastLocation
- an integer specifying the last divider location in pixels, from the left (or upper) edge of the pane to the left (or upper) edge of the dividerpublic int getLastDividerLocation()
@BeanProperty(enumerationValues={"JSplitPane.HORIZONTAL_SPLIT","JSplitPane.VERTICAL_SPLIT"}, description="The orientation, or how the splitter is divided.") public void setOrientation(int orientation)
orientation
- an integer specifying the orientationIllegalArgumentException
- if orientation is not one of: HORIZONTAL_SPLIT or VERTICAL_SPLIT.public int getOrientation()
@BeanProperty(description="Whether the child components are continuously redisplayed and laid out during user intervention.") public void setContinuousLayout(boolean newContinuousLayout)
continuousLayout
property, which must be true
for the child components to be continuously redisplayed and laid out during user intervention. The default value of this property is look and feel dependent. Some look and feels might not support continuous layout; they will ignore this property.newContinuousLayout
- true
if the components should continuously be redrawn as the divider changes positionpublic boolean isContinuousLayout()
continuousLayout
property.continuousLayout
property@BeanProperty(description="Specifies how to distribute extra space when the split pane resizes.") public void setResizeWeight(double value)
value
- as described aboveIllegalArgumentException
- if value
is < 0 or > 1public double getResizeWeight()
public void resetToPreferredSizes()
JSplitPane
layout based on the preferred size of the children components. This will likely result in changing the divider location.@BeanProperty(description="The location of the divider.") public void setDividerLocation(double proportionalLocation)
JSplitPane
's size. This method is implemented in terms of setDividerLocation(int)
. This method immediately changes the size of the split pane based on its current size. If the split pane is not correctly realized and on screen, this method will have no effect (new divider location will become (current size * proportionalLocation) which is 0).
proportionalLocation
- a double-precision floating point value that specifies a percentage, from zero (top/left) to 1.0 (bottom/right)IllegalArgumentException
- if the specified location is < 0 or > 1.0@BeanProperty(description="The location of the divider.") public void setDividerLocation(int location)
setLastDividerLocation
.location
- an int specifying a UI-specific value (typically a pixel count)public int getDividerLocation()
setDividerLocation
. The value returned from this method may differ from the actual divider location (if setDividerLocation
was passed a value bigger than the current size).@BeanProperty(bound=false, description="The minimum location of the divider from the L&F.") public int getMinimumDividerLocation()
null
@BeanProperty(bound=false) public int getMaximumDividerLocation()
null
public void remove(Component component)
component
from the pane. Resets the leftComponent
or rightComponent
instance variable, as necessary.public void remove(int index)
Component
at the specified index. Updates the leftComponent
and rightComponent
instance variables as necessary, and then messages super.public void removeAll()
leftComonent
and rightComponent
instance variables.@BeanProperty(hidden=true) public boolean isValidateRoot()
revalidate
on any descendant of this JSplitPane
will cause a request to be queued that will validate the JSplitPane
and all its descendants.isValidateRoot
in class JComponent
protected void addImpl(Component comp, Object constraints, int index)
constraints
identifies the left/top or right/bottom child component, and a component with that identifier was previously added, it will be removed and then comp
will be added in its place. If constraints
is not one of the known identifiers the layout manager may throw an IllegalArgumentException
. The possible constraints objects (Strings) are:
constraints
object is null
, the component is added in the first available position (left/top if open, else right/bottom).addImpl
in class Container
comp
- the component to addconstraints
- an Object
specifying the layout constraints (position) for this componentindex
- an integer specifying the index in the container's list.IllegalArgumentException
- if the constraints
object does not match an existing componentprotected void paintChildren(Graphics g)
finishedPaintingChildren
after super has been messaged, as well as painting the border.paintChildren
in class JComponent
g
- the Graphics
context within which to paintprotected String paramString()
JSplitPane
. This method is intended to be used only for debugging purposes, and the content and format of the returned string may vary between implementations. The returned string may be empty but may not be null
.paramString
in class JComponent
JSplitPane
.@BeanProperty(bound=false, expert=true, description="The AccessibleContext associated with this SplitPane.") public AccessibleContext getAccessibleContext()
getAccessibleContext
in interface Accessible
getAccessibleContext
in class Component
© 1993, 2023, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from Debian's OpenJDK Development Kit package.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Various third party code in OpenJDK is licensed under different licenses (see Debian package).
Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
https://docs.oracle.com/en/java/javase/21/docs/api/java.desktop/javax/swing/JSplitPane.html