
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Set Orientation and Split Components Along Y-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.VERTICAL_SPLIT); split.setTopComponent(one); split.setBottomComponent(two);
The following is an example to set Orientation and split components along y-axis −
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.VERTICAL_SPLIT); split.setTopComponent(one); split.setBottomComponent(two); frame.add(split, BorderLayout.NORTH); frame.setSize(550, 250); frame.setVisible(true); } }
This will produce the following output −
Advertisements