- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to create JSplitPane to divide components in Java?
At first, set two components which we will dividing −
JComponent one = new JLabel("Label One"); one.setBorder(BorderFactory.createLineBorder(Color.yellow)); JComponent two = new JLabel("Label Two"); two.setBorder(BorderFactory.createLineBorder(Color.orange));
Now, split it using SplitPane −
Example
package my; import java.awt.BorderLayout; import java.awt.Color; import javax.swing.BorderFactory; import javax.swing.JComponent; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JSplitPane; public class SwingDemo { public static void main(String[] a) { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JComponent one = new JLabel("Label One"); one.setBorder(BorderFactory.createLineBorder(Color.yellow)); JComponent two = new JLabel("Label Two"); two.setBorder(BorderFactory.createLineBorder(Color.orange)); JComponent three = new JLabel("Label Three"); three.setBorder(BorderFactory.createLineBorder(Color.blue)); JComponent four = new JLabel("Label Four"); four.setBorder(BorderFactory.createLineBorder(Color.green)); JSplitPane split1 = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT); split1.setLeftComponent(one); split1.setRightComponent(two); JSplitPane split2 = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT); split2.setLeftComponent(three); split2.setRightComponent(four); frame.add(split1, BorderLayout.NORTH); frame.add(split2, BorderLayout.SOUTH); frame.setSize(550, 250); frame.setVisible(true); } }
Output
- Related Articles
- How to create a nested JSplitPane in Java?
- How can we set a background color to JSplitPane in Java?
- How to create Glue to fill the space between neighbouring components in Java?
- How to create a Box to display components from left to right in Java
- How to create an invisible fixed width component between two components in Java?
- How to create an invisible fixed height component between two components in Java?
- How to deal with reusable components in Selenium Java?
- How to divide an array into half in java?
- How to capture divide by zero exception in Java?
- How can we hide left/right pane of a JSplitPane programmatically in Java?
- How to arrange components in a Flow to be right-justified in Java?
- How to arrange components in a FlowLayout to be left-justified in Java?
- How to set Raised and Lowered EtchedBorder for components in Java?
- How to add components with a Relative X Position in Java
- How to set a different look and feels to swing components in Java?

Advertisements