分割面板:
JSplitPane(方向),默认水平分割。JSplitPane.HORIZONTAL_SPLIT,JSplitPane.VERTICAL_SPLIT
JSplitPane(方向,boolean newContinuousLayout),第二个参数是否重绘,即true分隔条无拖影
import javax.swing.*;
import java.awt.*;
public class Demo extends JFrame {
public Demo() {//窗体
setTitle("分割面板");
setBounds(100, 100, 500, 400);
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
Container c = getContentPane();
JSplitPane sp = new JSplitPane();//分割面板,默认水平分割且左右各一个button
sp.setLeftComponent(new JLabel("左标签"));//左边放置标签
c.add(sp);
JSplitPane sp_v = new JSplitPane(JSplitPane.VERTICAL_SPLIT);//垂直分割面板
sp_v.setTopComponent(new JLabel("上标签"));
sp_v.setBottomComponent(new JLabel("下标签"));
sp.setRightComponent(sp_v);//放置在右侧
//分隔条的一些属性
sp_v.setDividerSize(20);//分隔条宽度20像素
sp_v.setDividerLocation(100);//分隔条距离上方100像素
sp.setDividerLocation(100);//分隔条距离左方100像素
sp_v.setContinuousLayout(true);//无拖影
sp_v.setOneTouchExpandable(true);//一键展开三角按钮
}
public static void main(String[] args) {
Demo frame = new Demo();//实例化窗体
frame.setVisible(true);//显示窗体
}
}