import javax.swing.*;
import java.awt.Dimension;
public class JSplitPaneDemo
{
public static void main (String[] args)
{
JButton button = new JButton ("button");
JLabel label = new JLabel ("label");
JSplitPane splitPane = new JSplitPane ();
splitPane.setOneTouchExpandable (true);//是该分隔面板的分隔条显示出箭头
splitPane.setContinuousLayout (true);
splitPane.setPreferredSize (new Dimension (500,600));//设置大小
splitPane.setOrientation (JSplitPane.HORIZONTAL_SPLIT);
splitPane.setLeftComponent (button);//same as: splitPane.setTopComponent(button);
splitPane.setRightComponent (label);//same as: splitPane.setBottomComponent(label);
splitPane.setDividerSize (5);//设置分隔条的粗细
splitPane.setDividerLocation(200);//设置分隔条的位置,基于setPreferredSize方法中的值,
//此处为200/500,大概在中间靠左
JFrame frame = new JFrame ("JSplitPanelDemo");
frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
frame.setVisible (true);
frame.setContentPane (splitPane);
frame.pack ();//此方法必须在加载splitPane之后调用
}
}
评论