Module java.desktop
Package javax.swing

Class JSplitPane

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible

@JavaBean(defaultProperty="UI") public class JSplitPane extends JComponent implements 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:
  • Field Details

    • VERTICAL_SPLIT

      public static final int VERTICAL_SPLIT
      Vertical split indicates the Components are split along the y axis. For example the two Components will be split one on top of the other.
      See Also:
    • HORIZONTAL_SPLIT

      public static final int HORIZONTAL_SPLIT
      Horizontal split indicates the Components are split along the x axis. For example the two Components will be split one to the left of the other.
      See Also:
    • LEFT

      public static final String LEFT
      Used to add a Component to the left of the other Component.
      See Also:
    • TOP

      public static final String TOP
      Used to add a Component above the other Component.
      See Also:
    • BOTTOM

      public static final String BOTTOM
      Used to add a Component below the other Component.
      See Also:
    • DIVIDER

      public static final String DIVIDER
      Used to add a Component that will represent the divider.
      See Also:
    • ORIENTATION_PROPERTY

      public static final String ORIENTATION_PROPERTY
      Bound property name for orientation (horizontal or vertical).
      See Also:
    • CONTINUOUS_LAYOUT_PROPERTY

      public static final String CONTINUOUS_LAYOUT_PROPERTY
      Bound property name for continuousLayout.
      See Also:
    • DIVIDER_SIZE_PROPERTY

      public static final String DIVIDER_SIZE_PROPERTY
      Bound property name for border.
      See Also:
    • ONE_TOUCH_EXPANDABLE_PROPERTY

      public static final String ONE_TOUCH_EXPANDABLE_PROPERTY
      Bound property for oneTouchExpandable.
      See Also:
    • LAST_DIVIDER_LOCATION_PROPERTY

      public static final String LAST_DIVIDER_LOCATION_PROPERTY
      Bound property for lastLocation.
      See Also:
    • DIVIDER_LOCATION_PROPERTY

      public static final String DIVIDER_LOCATION_PROPERTY
      Bound property for the dividerLocation.
      Since:
      1.3
      See Also:
    • RESIZE_WEIGHT_PROPERTY

      public static final String RESIZE_WEIGHT_PROPERTY
      Bound property for weight.
      Since:
      1.3
      See Also:
    • orientation

      protected int orientation
      How the views are split.
    • continuousLayout

      protected boolean continuousLayout
      Whether or not the views are continuously redisplayed while resizing.
    • leftComponent

      protected Component leftComponent
      The left or top component.
    • rightComponent

      protected Component rightComponent
      The right or bottom component.
    • dividerSize

      protected int dividerSize
      Size of the divider.
    • oneTouchExpandable

      protected boolean oneTouchExpandable
      Is a little widget provided to quickly expand/collapse the split pane?
    • lastDividerLocation

      protected int lastDividerLocation
      Previous location of the split pane.
  • Constructor Details

    • JSplitPane

      public JSplitPane()
      Creates a new JSplitPane configured to arrange the child components side-by-side horizontally, using two buttons for the components.
    • JSplitPane

      @ConstructorProperties("orientation") public JSplitPane(int newOrientation)
      Creates a new JSplitPane configured with the specified orientation.
      Parameters:
      newOrientation - JSplitPane.HORIZONTAL_SPLIT or JSplitPane.VERTICAL_SPLIT
      Throws:
      IllegalArgumentException - if orientation is not one of HORIZONTAL_SPLIT or VERTICAL_SPLIT.
    • JSplitPane

      public JSplitPane(int newOrientation, boolean newContinuousLayout)
      Creates a new JSplitPane with the specified orientation and redrawing style.
      Parameters:
      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 redraw
      Throws:
      IllegalArgumentException - if orientation is not one of HORIZONTAL_SPLIT or VERTICAL_SPLIT
    • JSplitPane

      public JSplitPane(int newOrientation, Component newLeftComponent, Component newRightComponent)
      Creates a new JSplitPane with the specified orientation and the specified components.
      Parameters:
      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 pane
      newRightComponent - the Component that will appear on the right of a horizontally-split pane, or at the bottom of a vertically-split pane
      Throws:
      IllegalArgumentException - if orientation is not one of: HORIZONTAL_SPLIT or VERTICAL_SPLIT
    • JSplitPane

      public JSplitPane(int newOrientation, boolean newContinuousLayout, Component newLeftComponent, Component newRightComponent)
      Creates a new JSplitPane with the specified orientation and redrawing style, and with the specified components.
      Parameters:
      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 redraw
      newLeftComponent - the Component that will appear on the left of a horizontally-split pane, or at the top of a vertically-split pane
      newRightComponent - the Component that will appear on the right of a horizontally-split pane, or at the bottom of a vertically-split pane
      Throws:
      IllegalArgumentException - if orientation is not one of HORIZONTAL_SPLIT or VERTICAL_SPLIT
  • Method Details

    • setUI

      public void setUI(SplitPaneUI ui)
      Sets the L&F object that renders this component.
      Parameters:
      ui - the SplitPaneUI L&F object
      See Also:
    • getUI

      @BeanProperty(bound=false, expert=true, description="The L&F object that renders this component.") public SplitPaneUI getUI()
      Returns the SplitPaneUI that is providing the current look and feel.
      Overrides:
      getUI in class JComponent
      Returns:
      the SplitPaneUI object that renders this component
    • updateUI

      public void updateUI()
      Notification from the UIManager that the L&F has changed. Replaces the current UI object with the latest version from the UIManager.
      Overrides:
      updateUI in class JComponent
      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:
      getUIClassID in class JComponent
      Returns:
      the string "SplitPaneUI"
      See Also:
    • setDividerSize

      @BeanProperty(description="The size of the divider.") public void setDividerSize(int newSize)
      Sets the size of the divider. Divider sizes newSize < 0 are 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

      public void setLeftComponent(Component comp)
      Sets the component to the left (or above) the divider.
      Parameters:
      comp - the Component to 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 Component displayed 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 - the Component to display in that position
    • getTopComponent

      public Component getTopComponent()
      Returns the component above, or to the left of the divider.
      Returns:
      the Component displayed 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 - the Component to display in that position
    • getRightComponent

      public Component getRightComponent()
      Returns the component to the right (or below) the divider.
      Returns:
      the Component displayed 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 - the Component to display in that position
    • getBottomComponent

      public Component getBottomComponent()
      Returns the component below, or to the right of the divider.
      Returns:
      the Component displayed 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 the oneTouchExpandable property, which must be true for the JSplitPane t