- Example - Home
- Example - Environment Setup
- Example - Borders
- Example - Buttons
- Example - CheckBoxes
- Example - Combo Boxes
- Example - Color Choosers
- Example - Dialogs
- Example - Editor Panes
- Example - File Choosers
- Example - Formatted TextFields
- Example - Frames
- Example - Lists
- Example - Layouts
- Example - Menus
- Example - Password Fields
- Example - Progress Bars
- Example - Scroll Panes
- Example - Sliders
- Example - Spinners
- Example - Tables
- Example - Toolbars
- Example - Tree
Swing Examples - Split Pane with horizontal split
The class SplitPane allows to have movable split between two panels.
Example
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JSplitPane;
import javax.swing.JTextField;
public class SwingTester {
public static void main(String[] args) {
createWindow();
}
private static void createWindow() {
JFrame frame = new JFrame("Swing Tester");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
createUI(frame);
frame.setSize(560, 200);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
private static void createUI(final JFrame frame){
JPanel buttonPanel = new JPanel(new FlowLayout());
buttonPanel.add(new JButton("OK"));
buttonPanel.add(new JButton("Cancel"));
JPanel textBoxPanel = new JPanel(new FlowLayout());
textBoxPanel.add(new JLabel("Name:"));
textBoxPanel.add(new JTextField(20));
JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,buttonPanel, textBoxPanel);
splitPane.setOneTouchExpandable(true);
splitPane.setDividerLocation(150);
frame.getContentPane().add(splitPane, BorderLayout.CENTER);
}
}
Output
swingexamples_layouts.htm
Advertisements