Open In App

Java Swing | JSplitPane with Examples

Last Updated : 14 Oct, 2019
Comments
Improve
Suggest changes
1 Like
Like
Report
JSplitPane is a part of Java Swing. JSplitPane is used to divide only two components. JSplitPane is to use resize the components . By using the JSplitPane the user can manually resize the component till its minimum size . JSplitPane can be of two types, one is the vertical and horizontal splitpane Constructor of JSplitPane are:
  1. JSplitPane() : creates a new split pane that is oriented horizontally
  2. JSplitPane(int o) : creates a new split pane with orientation mentioned.
  3. JSplitPane(int o, boolean r) : creates a new split pane with orientation and redrawing style mentioned.
  4. JSplitPane(int o, boolean r, Component l, Component r) : creates a new split pane with orientation, redrawing style and left and right component mentioned.
  5. JSplitPane(int o, Component l, Component r): creates a new split pane with orientation and left and right component mentioned.
Commonly used Functions of JSplitPane are :
  1. getOrientation() : returns the orientation of the split pane
  2. getRightComponent() : returns the right component of the splitpane
  3. getTopComponent() : returns the top component of the splitpane
  4. isContinuousLayout() :returns the continuous layout property
  5. getBottomComponent() : returns the Bottom component of the splitpane
  6. setRightComponent(Component c) : the right component of the splitpane is set to c
  7. setLeftComponent(Component c) : the left component of the splitpane is set to c
  8. setTopComponent(Component c) : the top component of the splitpane is set to c
  9. setBottomComponent(Component c) : the bottom component of the splitpane is set to c
  10. setUI(SplitPaneUI ui) : Sets the Look and feel object that renders this component.
  11. setResizeWeight(double v) :Specifies how to distribute extra space when the size of the split pane changes.
  12. setOneTouchExpandable(boolean n) : Sets the value of the oneTouchExpandable property, whichwhen true provides a UI widget that can collapse or expand the components on click
  13. setDividerLocation(int l) : Sets the location of the divider.
  14. setDividerSize(int n) : Sets the size of the divider.
  15. setLastDividerLocation(int n) : Sets the last location the divider.
  16. setDividerLocation(double p) : Sets the divider location as a percentage of the JSplitPane's size.
  17. setContinuousLayout(boolean n) : Sets the value of the continuousLayout property, which must be true for the child components to be continuously redisplayed .
  18. remove(int index) : removes the Component at the specified index.
  19. remove(Component c) : Removes the child component from the pane.
  20. isOneTouchExpandable() : returns the oneTouchExpandable property.
  21. isContinuousLayout() : returns the continuousLayout property.
  22. getMinimumDividerLocation() : returns the minimum location of the divider .
  23. getMaximumDividerLocation() : Returns the maximum location of the divider .
  24. getDividerSize() : Returns the size of the divider.
  25. getDividerLocation() : returns the last value passed to setDividerLocation.
  26. addImpl(Component c, Object co, int i) : adds the specified component to this split pane.
  27. setUI(SplitPaneUI ui) : sets the look and feel object that renders this component.
  28. getUI() : returns the look and feel object that renders this component.
  29. paramString() : returns a string representation of this JSplitPane.
  30. getUIClassID() : returns the name of the Look and feel class that renders this component.
  31. getAccessibleContext() : gets the AccessibleContext associated with this JSplitPane.
The Following programs will illustrate the use of JSplitPane 1. Program to create a horizontal JSplitPane to separate two text areas
Output : 2.Program to create a Vertical JSplitPane to separate two text areas
Output : 2. Java Program to create nested JSplitPane, one of them is one Touch Expandable
Output: Note : This above programs might not run in an online compiler please use an offline IDE

Next Article
Practice Tags :

Similar Reads