- 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
Advertisements
To Continue Learning Please Login
Login with Google