public class JSplitPaneKnow extends JFrame
{
JSplitPane jSplitPane;
JPanel jPanelRed;
JPanel jPanelBlue;
public JSplitPaneKnow()
{
this.setBounds(300, 100, 400, 400);
this.setTitle("分屏设计");
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jPanelBlue = new JPanel();
jPanelRed = new JPanel();
//第一个参数表示分屏的方式:左右HORIZONTAL_SPLIT,上下VERTICAL_SPLIT
jSplitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT,jPanelBlue,jPanelRed);
jPanelBlue.setBackground(Color.BLUE);
jPanelRed.setBackground(Color.RED);
this.add(jSplitPane);
//设置分割线的位置
jSplitPane.setDividerLocation(200);
//设置分割线的大小
jSplitPane.setDividerSize(5);
//设置分割线是否可以随意拉动
jSplitPane.setEnabled(false);
}
public static void main(String[] args)
{
JSplitPaneKnow jSplitPaneKnow = new JSplitPaneKnow();
jSplitPaneKnow.setVisible(true);
}
}