JSplitPane
来源:互联网 发布:Windows icinga监控 编辑:程序博客网 时间:2024/05/22 05:03
JSplitPaneDemo.java
01 package cn.rolia.learning.swing;
02 import javax.swing.*;
03 import java.awt.Dimension;
04 public class JSplitPaneDemo
05 {
06 public static void main (String[] args)
07 {
08
09 JButton button = new JButton ("button");
10 JLabel label = new JLabel ("label");
11
12 JSplitPane splitPane = new JSplitPane ();
13 splitPane.setOneTouchExpandable (true);//是该分隔面板的分隔条显示出箭头
14 splitPane.setContinuousLayout (true);
15 splitPane.setPreferredSize (new Dimension (500,600));//设置大小
16 splitPane.setOrientation (JSplitPane.HORIZONTAL_SPLIT);
17 splitPane.setLeftComponent (button);//same as: splitPane.setTopComponent(button);
18 splitPane.setRightComponent (label);//same as: splitPane.setBottomComponent(label);
19 splitPane.setDividerSize (5);//设置分隔条的粗细
20 splitPane.setDividerLocation(200);//设置分隔条的位置,基于setPreferredSize方法中的值,
21 //此处为200/500,大概在中间靠左
22
23 JFrame frame = new JFrame ("JSplitPanelDemo");
24 frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
25 frame.setVisible (true);
26 frame.setContentPane (splitPane);
27 frame.pack ();//此方法必须在加载splitPane之后调用
28 }
29 }