- 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 nested JSplitPane in Java?
Let us first create three components −
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));
Now, we will split one and two components.
JSplitPane split1 = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, one, two); split1.setDividerLocation(0.5); split1.setDividerSize(2);
After that the above splitted pane would be splitted with component three making the process nested −
JSplitPane split2 = new JSplitPane(JSplitPane.VERTICAL_SPLIT,split1, three ); split2.setDividerLocation(0.9); split2.setDividerSize(2);
The following is an example to create nested JSplitPane −
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)); JSplitPane split1 = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, one, two); split1.setDividerLocation(0.5); split1.setDividerSize(2); JSplitPane split2 = new JSplitPane(JSplitPane.VERTICAL_SPLIT,split1, three ); split2.setDividerLocation(0.9); split2.setDividerSize(2); frame.add(split2,BorderLayout.CENTER); frame.setSize(550, 250); frame.setVisible(true); } }
Output
- Related Articles
- How to create JSplitPane to divide components in Java?
- How can we set a background color to JSplitPane in Java?
- How to create a nested index in MongoDB?
- Can we create nested TitiledBorder in Java?
- How can we hide left/right pane of a JSplitPane programmatically in Java?
- How to create nested Python dictionary?
- How to create double nested array in MongoDB?
- How to create nested while loop in C#?
- How do you create nested dict in Python?
- How to create nested test suites for Selenium IDE?
- How to create data frame using nested list elements in R?
- Create nested JSON object in PHP?
- How to create a thread in Java
- How to create a HashSet in Java?
- How can we parse a nested JSON object in Java?

Advertisements