Create a Horizontal Split JSplitPane in Java
Description
The following code shows how to create a Horizontal Split JSplitPane.
Example
import java.awt.BorderLayout;
import java.awt.Dimension;
/*from w ww.j ava 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.HORIZONTAL_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.
Home »
Java Tutorial »
Swing »
Java Tutorial »
Swing »