by Dinesh Thakur Category: Swing

A split pane is a lightweight container that allows you to arrange two components (only two) side by side horizontally or vertically in a single pane. The display areas of both the components can also be adjusted at the runtime by the user. A split pane is an object of JSplitPane class.

Some of the constructors defined by JSplitPane class are as follows.

JSplitPane ()

JSpliPane(int orientation, boolean continuousLayout)

JSplitPane(int orientation, Component TopOrLeft,BottomOrRight)

JSplitPane(int orientation, boolean continuousLayout, Component TopOrLeft, Component BottomOrRight)


orientation specifies how components will be arranged - can have one of the two values:


continuousLayout can have one of the two values: true,if the components are resizable

when divider is moved, otherwise false (default value)

TopOrLeft specifies the object to be placed at top or left

BottomOrRight specifies the object to be placed at bottom or right

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class JavaExampleSplitPaneInJApplet extends JApplet implements ActionListener
    JButton BtnTch,BtnSpltHoriz,BtnDvdrSz;
    JTextField TxtOne = new JTextField("Text Field One");
    JTextField TxtTwo = new JTextField("Text Field Two");
    JSplitPane SpltPn = new JSplitPane(JSplitPane.VERTICAL_SPLIT,TxtOne,TxtTwo);
    public void init()
        Container Cntnr = getContentPane();
        JPanel Pnl = new JPanel();
        BtnTch = new JButton("One-Touch Expandable");
        BtnSpltHoriz = new JButton("Horizontal Split");
        BtnDvdrSz = new JButton("Extend Divider Size");
        Cntnr.add(SpltPn, BorderLayout.CENTER);
        Cntnr.add(Pnl, BorderLayout.SOUTH);
        public void actionPerformed(ActionEvent e1)
            if(e1.getSource() == BtnTch)
                 if(e1.getSource() ==BtnSpltHoriz)
                      if(e1.getSource() == BtnDvdrSz)
                           SpltPn.setDividerSize(SpltPn.getDividerSize() + 10);
/*<APPLET CODE=JavaExampleSplitPaneInJApplet.class WIDTH=610 HEIGHT=210></APPLET>*/

JSplitPane Java Example

About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.C.A, MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.

Related Articles