- 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 a left-right split pane in Java?
To create a left-right split pane, let us create two components and split them −
JComponent one = new JLabel("Left Split"); one.setBorder(BorderFactory.createLineBorder(Color.MAGENTA)); JComponent two = new JLabel("Right Split"); two.setBorder(BorderFactory.createLineBorder(Color.ORANGE));
Now, we will split them. The two components will be split one to the left of the other using HORIZONTAL_PANE constant −
JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, one, two);
The following is an example to create a left-right split pane in Java −
Example
package my; 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("SplitPane Demo"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JComponent one = new JLabel("Left Split"); one.setBorder(BorderFactory.createLineBorder(Color.MAGENTA)); JComponent two = new JLabel("Right Split"); two.setBorder(BorderFactory.createLineBorder(Color.ORANGE)); JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, one, two); frame.add(splitPane); frame.setSize(550, 250); frame.setVisible(true); } }
This will produce the following output −
- Related Articles
- How to create a top-bottom split pane in Java?
- How can we hide left/right pane of a JSplitPane programmatically in Java?
- How to create a Box to display components from left to right in Java
- How to create a scroll pane using JavaFX?
- How to create a border pane using JavaFX?
- How to create a flow pane using JavaFX?
- How to create a grid pane using JavaFX?
- How to create Titled Pane using JavaFx?
- Create Left to Right slide animation in Android?
- Create a paragraph with a right-to-left direction in HTML5
- How to create an anchor pane using JavaFX?
- How to add JList to Scroll pane in Java?
- How to move the horizontal slider right-to-left in Java?
- How to Create LEFT-RIGHT Alignment of Containers with CSS Flex
- Create Left to Right slide animation in Android using Kotlin.

Advertisements