This is a Java Program to Create a Split Pane with Two Parts to Display Button and Display Text inside Text Area when Button is Clicked
We have to write a program in Java such that it creates a vertically split frame where the left part consists of few push buttons and the right part consists of a text area. When a push button is clicked, the button is displayed in the text area.
To create a Split Pane, we have the following sets of input and output.
1. To view the frame:
At the execution of the program, it is expected that a vertically split frame appears. left part frame displays 5 push buttons and right part displays text area
2. To view text in the text area:
Suppose there are 5 push buttons in left part of frame (Button 1, Button 2, Button 3, Button 4, Button 5) When any push button is clicked for example (Button 1 is clicked), then it is expected that the text area shows "Button clicked: Button 1".
1. Create a frame and two panels for the left part and the right part.
2. Add few buttons to the left part, and a text area to the right part.
3. Create a Split Pane using JSplitPane and add the left and right components to it.
4. Add the Split Pane to the frame and display the frame.
Here is source code of the Java Program to create a Split Pane. The program is successfully compiled and tested using javac compiler on Fedora 30. The program output is also shown below.
/*Java Program to Create a Split Pane*/
class Split_Pane implements ActionListener
static JTextArea text;
public static void main(String args)
//Create a frame
JFrame frame = new JFrame("Tabbed Pane");
//Create an object of the class
Split_Pane obj = new Split_Pane();
//Create Panel 1 for Left Part
JPanel panel1 = new JPanel(false);
JButton button=new JButton;
button[i]=new JButton("Button "+(i+1));
//Create Panel 2 for Right Part
JPanel panel2 = new JPanel(false);
//Create a split pane
JSplitPane pane = new JSplitPane(SwingConstants.VERTICAL);
//Add split pane to frame
//Display the frame
//Function to display the button clicked
public void actionPerformed(ActionEvent e)
text.setText("Button Clicked : "+button);
1. Panel 1 is the left component of the split pane, and it consists of push buttons.
2. Panel 2 is the right component of the split pane, and it consists of a text area.
3. A vertical split pane is created using JSplitPane. To set the spit orientation to vertical SwingConstants.VERTICAL is used.
4. The left and right components are set using setLeftComponent and setRightComponent respectively.
5. The split pane is added to the frame and the frame is displayed.
6. When a button is clicked, the actionPerformed function is called by the ActionListener and it displays the button clicked in the text area.
Here’s the run time test cases to create a Split Pane.
Sanfoundry Global Education & Learning Series – Java Programs.