- 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 set orientation and split components along x-axis in Java?
Let us first create components to split. Here. We have two labels −
JComponent one = new JLabel("Label One"); one.setBorder(BorderFactory.createLineBorder(Color.red)); JComponent two = new JLabel("Label Two"); two.setBorder(BorderFactory.createLineBorder(Color.blue));
Now, set orientation and split along x-axis with HORIZONTAL_SPLIT −
JSplitPane split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT); split.setLeftComponent(one); split.setRightComponent(two);
The following is an example to set orientation and split components along x-axis in Java −
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.red)); JComponent two = new JLabel("Label Two"); two.setBorder(BorderFactory.createLineBorder(Color.blue)); JSplitPane split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT); split.setLeftComponent(one); split.setRightComponent(two); frame.add(split, BorderLayout.NORTH); frame.setSize(550, 250); frame.setVisible(true); } }
This will produce the following output −
- Related Articles
- Java Program to set Orientation and split components along y-axis
- How to set the alignment of the JLabel content along the X axis in Java?
- How to set the alignment of the JLabel content along the X axis on the left in Java
- Set the alignment of the JLabel content along the X axis on the right in Java
- How to set the alignment of the JLabel content along the Y axis in Java?
- How to change the orientation and font size of x-axis labels using ggplot2 in R?
- How to shift a graph along the X-axis in matplotlib?
- How to set Raised and Lowered EtchedBorder for components in Java?
- How to set X-axis values in Matplotlib Python?
- How to set the alignment of the JLabel content along the Y axis on the top in Java
- How to set the alignment of the JLabel content along the Y axis in the bottom with Java
- Transform the element along with x-axis and y-axis with CSS
- How to crop an image along the X-axis using FabricJS?
- How to set a different look and feels to swing components in Java?
- How to add components with relative X and Y Coordinates in Java?

Advertisements