Java Swing | JSplitPane with Examples Last Updated : 14 Oct, 2019 Comments Improve Suggest changes Like Article 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: JSplitPane() : creates a new split pane that is oriented horizontally JSplitPane(int o) : creates a new split pane with orientation mentioned. JSplitPane(int o, boolean r) : creates a new split pane with orientation and redrawing style mentioned. JSplitPane(int o, boolean r, Component l, Component r) : creates a new split pane with orientation, redrawing style and left and right component mentioned. 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 : getOrientation() : returns the orientation of the split pane getRightComponent() : returns the right component of the splitpane getTopComponent() : returns the top component of the splitpane isContinuousLayout() :returns the continuous layout property getBottomComponent() : returns the Bottom component of the splitpane setRightComponent(Component c) : the right component of the splitpane is set to c setLeftComponent(Component c) : the left component of the splitpane is set to c setTopComponent(Component c) : the top component of the splitpane is set to c setBottomComponent(Component c) : the bottom component of the splitpane is set to c setUI(SplitPaneUI ui) : Sets the Look and feel object that renders this component. setResizeWeight(double v) :Specifies how to distribute extra space when the size of the split pane changes. 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 setDividerLocation(int l) : Sets the location of the divider. setDividerSize(int n) : Sets the size of the divider. setLastDividerLocation(int n) : Sets the last location the divider. setDividerLocation(double p) : Sets the divider location as a percentage of the JSplitPane's size. setContinuousLayout(boolean n) : Sets the value of the continuousLayout property, which must be true for the child components to be continuously redisplayed . remove(int index) : removes the Component at the specified index. remove(Component c) : Removes the child component from the pane. isOneTouchExpandable() : returns the oneTouchExpandable property. isContinuousLayout() : returns the continuousLayout property. getMinimumDividerLocation() : returns the minimum location of the divider . getMaximumDividerLocation() : Returns the maximum location of the divider . getDividerSize() : Returns the size of the divider. getDividerLocation() : returns the last value passed to setDividerLocation. addImpl(Component c, Object co, int i) : adds the specified component to this split pane. setUI(SplitPaneUI ui) : sets the look and feel object that renders this component. getUI() : returns the look and feel object that renders this component. paramString() : returns a string representation of this JSplitPane. getUIClassID() : returns the name of the Look and feel class that renders this component. 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 Java // Java Program to create a horizontal JSplitPane // to separate two text areas import javax.swing.event.*; import java.awt.*; import javax.swing.*; class solve extends JFrame { // frame static JFrame f; // text areas static JTextArea t1, t2; // main class public static void main(String[] args) { // create a new frame f = new JFrame("frame"); // create a object solve s = new solve(); // create a panel JPanel p1 = new JPanel(); JPanel p = new JPanel(); // create text areas t1 = new JTextArea(10, 10); t2 = new JTextArea(10, 10); // set texts t1.setText("this is first text area"); t2.setText("this is second text area"); // add text area to panel p1.add(t1); p.add(t2); // create a splitpane JSplitPane sl = new JSplitPane(SwingConstants.HORIZONTAL, p1, p); // add panel f.add(sl); // set the size of frame f.setSize(300, 300); f.show(); } } Output : 2.Program to create a Vertical JSplitPane to separate two text areas Java // Java Program to create a vertical // JSplitPane to separate two text areas import javax.swing.event.*; import java.awt.*; import javax.swing.*; class solve extends JFrame { // frame static JFrame f; // text areas static JTextArea t1, t2; // main class public static void main(String[] args) { // create a new frame f = new JFrame("frame"); // create a object solve s = new solve(); // create a panel JPanel p1 = new JPanel(); JPanel p = new JPanel(); // create text areas t1 = new JTextArea(10, 10); t2 = new JTextArea(10, 10); // set texts t1.setText("this is first text area"); t2.setText("this is second text area"); // add text area to panel p1.add(t1); p.add(t2); // create a splitpane JSplitPane sl = new JSplitPane(SwingConstants.VERTICAL, p1, p); // set Orientation for slider sl.setOrientation(SwingConstants.VERTICAL); // add panel f.add(sl); // set the size of frame f.setSize(300, 300); f.show(); } } Output : 2. Java Program to create nested JSplitPane, one of them is one Touch Expandable Java // Java Program to create nested JSplitPane, // one of them is one Touch Expandable import javax.swing.event.*; import java.awt.*; import javax.swing.*; class solve extends JFrame { // frame static JFrame f; // text areas static JTextArea t1, t2, t3, t4; // main class public static void main(String[] args) { // create a new frame f = new JFrame("frame"); // create a object solve s = new solve(); // create a panel JPanel p1 = new JPanel(); JPanel p = new JPanel(); JPanel p2 = new JPanel(); JPanel p3 = new JPanel(); // create text areas t1 = new JTextArea(10, 10); t2 = new JTextArea(10, 10); t3 = new JTextArea(10, 10); t4 = new JTextArea(10, 10); // set texts t1.setText("this is first text area"); t2.setText("this is second text area"); t3.setText("this is third text area"); t4.setText("this is fourth text area"); // add text area to panel p1.add(t1); p.add(t2); p2.add(t3); p3.add(t4); // create a splitpane JSplitPane sl = new JSplitPane(SwingConstants.VERTICAL, p1, p); JSplitPane s2 = new JSplitPane(SwingConstants.VERTICAL, p2, p3); // set Orientation for slider sl.setOrientation(SwingConstants.VERTICAL); s2.setOrientation(SwingConstants.VERTICAL); s2.setOneTouchExpandable(true); // set divider location sl.setDividerLocation(70); // set Layout for frame f.setLayout(new FlowLayout()); // add panel f.add(sl); f.add(s2); // set the size of frame f.setSize(600, 300); f.show(); } } Output: Note : This above programs might not run in an online compiler please use an offline IDE Comment More infoAdvertise with us Next Article Java Swing | JSplitPane with Examples andrew1234 Follow Improve Article Tags : Java Programming Language java-swing Practice Tags : Java Similar Reads Java Tutorial Java is a high-level, object-oriented programming language used to build web apps, mobile applications, and enterprise software systems. It is known for its Write Once, Run Anywhere capability, which means code written in Java can run on any device that supports the Java Virtual Machine (JVM).Java s 10 min read Java Interview Questions and Answers Java is one of the most popular programming languages in the world, known for its versatility, portability, and wide range of applications. Java is the most used language in top companies such as Uber, Airbnb, Google, Netflix, Instagram, Spotify, Amazon, and many more because of its features and per 15+ min read Java OOP(Object Oriented Programming) Concepts Java Object-Oriented Programming (OOPs) is a fundamental concept in Java that every developer must understand. It allows developers to structure code using classes and objects, making it more modular, reusable, and scalable.The core idea of OOPs is to bind data and the functions that operate on it, 13 min read Arrays in Java Arrays in Java are one of the most fundamental data structures that allow us to store multiple values of the same type in a single variable. They are useful for storing and managing collections of data. Arrays in Java are objects, which makes them work differently from arrays in C/C++ in terms of me 15+ min read Inheritance in Java Java Inheritance is a fundamental concept in OOP(Object-Oriented Programming). It is the mechanism in Java by which one class is allowed to inherit the features(fields and methods) of another class. In Java, Inheritance means creating new classes based on existing ones. A class that inherits from an 13 min read Collections in Java Any group of individual objects that are represented as a single unit is known as a Java Collection of Objects. In Java, a separate framework named the "Collection Framework" has been defined in JDK 1.2 which holds all the Java Collection Classes and Interface in it. In Java, the Collection interfac 15+ min read Java Exception Handling Exception handling in Java allows developers to manage runtime errors effectively by using mechanisms like try-catch block, finally block, throwing Exceptions, Custom Exception handling, etc. An Exception is an unwanted or unexpected event that occurs during the execution of a program, i.e., at runt 10 min read Java Programs - Java Programming Examples In this article, we will learn and prepare for Interviews using Java Programming Examples. From basic Java programs like the Fibonacci series, Prime numbers, Factorial numbers, and Palindrome numbers to advanced Java programs.Java is one of the most popular programming languages today because of its 8 min read Java Interface An Interface in Java programming language is defined as an abstract type used to specify the behaviour of a class. An interface in Java is a blueprint of a behaviour. A Java interface contains static constants and abstract methods. Key Properties of Interface:The interface in Java is a mechanism to 12 min read Polymorphism in Java Polymorphism in Java is one of the core concepts in object-oriented programming (OOP) that allows objects to behave differently based on their specific class type. The word polymorphism means having many forms, and it comes from the Greek words poly (many) and morph (forms), this means one entity ca 7 min read Like