Create a Vertical Split JSplitPane in Java

Description

The following code shows how to create a Vertical Split JSplitPane.

Example


import java.awt.BorderLayout;
import java.awt.Dimension;
//  w w w .j a  v a 2  s . co m
import javax.swing.JFrame;
import javax.swing.JSplitPane;
import javax.swing.JTextArea;

public class Main extends JFrame {

  static String sometext = "This is a test from java2s.com.";

  public Main() {
    setSize(450, 200);
    setDefaultCloseOperation(EXIT_ON_CLOSE);

    JTextArea jt1 = new JTextArea(sometext);
    JTextArea jt2 = new JTextArea(sometext);

    // Make sure our text boxes do line wrapping and have reasonable
    // minimum sizes.
    jt1.setLineWrap(true);
    jt2.setLineWrap(true);
    jt1.setMinimumSize(new Dimension(150, 150));
    jt2.setMinimumSize(new Dimension(150, 150));
    jt1.setPreferredSize(new Dimension(250, 200));
    JSplitPane sp = new JSplitPane(JSplitPane.VERTICAL_SPLIT, jt1, jt2);
    getContentPane().add(sp, BorderLayout.CENTER);
  }

  public static void main(String args[]) {
    Main ssb = new Main();
    ssb.setVisible(true);
  }
}

The code above generates the following result.

Create a Vertical Split 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