- 确定是左右分隔还是上下分隔,
- 设置两边的布局格式(可以不设置),
- 创建一个分隔容器类,
- 设置一些分隔面板的属性,
- 将内容分别放置到左右两侧
package PanelDemo;
import javax.swing.*;
import java.awt.*;
public class MyJSpane {
public MyJSpane() {
JButton b1 = new JButton("确定");
JButton b2 = new JButton("取消");
JButton b3 = new JButton("优秀");
JButton b4 = new JButton("良好");
JPanel panel1 =new JPanel();
JPanel panel2=new JPanel();
panel1.setLayout(new FlowLayout());
panel2.setLayout(new FlowLayout());
panel1.add(b1);
panel1.add(b2);
panel2.add(b3);
panel2.add(b4);
JSplitPane splitPane = new JSplitPane();
splitPane.setOneTouchExpandable(true);
splitPane.setContinuousLayout(true);
splitPane.setPreferredSize(new Dimension(100,200));
splitPane.setOrientation(JSplitPane.HORIZONTAL_SPLIT);
splitPane.setLeftComponent(panel1);
splitPane.setRightComponent(panel2);
splitPane.setDividerSize(3);
splitPane.setDividerLocation(50);
JFrame jf = new JFrame("测试窗口");
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jf.setVisible(true);
jf.setContentPane(splitPane);
jf.pack();
}
}
public class MyDemo {
public static void main(String[] args) {
MyJSpane myJSpane = new MyJSpane();
}
}
