
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
Create Top-Bottom Split Pane in Java
To create a top-bottom split pane, let us create two components and split them −
JComponent one = new JLabel("Top Split"); one.setBorder(BorderFactory.createLineBorder(Color.MAGENTA)); JComponent two = new JLabel("Bottom Split"); two.setBorder(BorderFactory.createLineBorder(Color.ORANGE));
Now, we will split them. The two components will be split one on top of the other using VERTICAL_PANE constant −
JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, one, two);
The following is an example to create a top-bottom 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("Top Split"); one.setBorder(BorderFactory.createLineBorder(Color.MAGENTA)); JComponent two = new JLabel("Bottom Split"); two.setBorder(BorderFactory.createLineBorder(Color.ORANGE)); JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, one, two); frame.add(splitPane); frame.setSize(550, 250); frame.setVisible(true); } }
Output
Advertisements