1 public class JSplitPaneKnow extends JFrame 2 { 3 JSplitPane jSplitPane; 4 JPanel jPanelRed; 5 JPanel jPanelBlue; 6 7 public JSplitPaneKnow() 8 { 9 this.setBounds(300, 100, 400, 400); 10 this.setTitle("分屏设计"); 11 this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 12 13 jPanelBlue = new JPanel(); 14 jPanelRed = new JPanel(); 15 //第一个参数表示分屏的方式:左右HORIZONTAL_SPLIT,上下VERTICAL_SPLIT 16 jSplitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT,jPanelBlue,jPanelRed); 17 18 jPanelBlue.setBackground(Color.BLUE); 19 jPanelRed.setBackground(Color.RED); 20 21 this.add(jSplitPane); 22 23 //设置分割线的位置 24 jSplitPane.setDividerLocation(200); 25 //设置分割线的大小 26 jSplitPane.setDividerSize(5); 27 //设置分割线是否可以随意拉动 28 jSplitPane.setEnabled(false); 29 } 30 public static void main(String[] args) 31 { 32 JSplitPaneKnow jSplitPaneKnow = new JSplitPaneKnow(); 33 jSplitPaneKnow.setVisible(true); 34 } 35 }