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)
where,
orientation specifies how components will be arranged – can have one of the two values:
HORIZONTAL_SPLIT and VERTICAL_SPLIT
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");
BtnTch.addActionListener(this);
Pnl.add(BtnTch);
BtnSpltHoriz = new JButton("Horizontal Split");
BtnSpltHoriz.addActionListener(this);
Pnl.add(BtnSpltHoriz);
BtnDvdrSz = new JButton("Extend Divider Size");
BtnDvdrSz.addActionListener(this);
Pnl.add(BtnDvdrSz);
Cntnr.add(SpltPn, BorderLayout.CENTER);
Cntnr.add(Pnl, BorderLayout.SOUTH);
}
public void actionPerformed(ActionEvent e1)
{
if(e1.getSource() == BtnTch)
{
SpltPn.setOneTouchExpandable(true);
}
if(e1.getSource() ==BtnSpltHoriz)
{
SpltPn.setOrientation(SpltPn.HORIZONTAL_SPLIT);
}
if(e1.getSource() == BtnDvdrSz)
{
SpltPn.setDividerSize(SpltPn.getDividerSize() + 10);
}
}
}
/*<APPLET CODE=JavaExampleSplitPaneInJApplet.class WIDTH=610 HEIGHT=210></APPLET>*/