Create a nested JSplitPane in Java

Description

The following code shows how to create a nested JSplitPane.

Example


import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
// w w w.  j  av  a2 s  .  c  o  m
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JSplitPane;

public class Main extends JFrame {
  protected JSplitPane split;

  public Main() {
    super("Simple Split Pane");
    setSize(400, 400);
    getContentPane().setLayout(new BorderLayout());

    JSplitPane spLeft = new JSplitPane(JSplitPane.VERTICAL_SPLIT, new JPanel(), new JPanel());
    spLeft.setDividerSize(8);
    spLeft.setContinuousLayout(true);

    JSplitPane spRight = new JSplitPane(JSplitPane.VERTICAL_SPLIT, new JPanel(), new JPanel());
    spRight.setDividerSize(8);
    spRight.setContinuousLayout(true);

    split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, spLeft, spRight);
    split.setContinuousLayout(false);
    split.setOneTouchExpandable(true);

    getContentPane().add(split, BorderLayout.CENTER);

    WindowListener wndCloser = new WindowAdapter() {
      public void windowClosing(WindowEvent e) {
        System.exit(0);
      }
    };
    addWindowListener(wndCloser);

    setVisible(true);
  }

  public static void main(String argv[]) {
    new Main();
  }
}

The code above generates the following result.

Create a nested JSplitPane in Java




















Home »
  Java Tutorial »
    Swing »




Action
Border
Color Chooser
Drag and Drop
Event
Font Chooser
JButton
JCheckBox
JComboBox
JDialog
JEditorPane
JFileChooser
JFormattedText
JFrame
JLabel
JList
JOptionPane
JPasswordField
JProgressBar
JRadioButton
JScrollBar
JScrollPane
JSeparator
JSlider
JSpinner
JSplitPane
JTabbedPane
JTable
JTextArea
JTextField
JTextPane
JToggleButton
JToolTip
JTree
Layout
Menu
Timer