BorderLayout布局展示

来源:互联网 发布:apache beam maven 编辑:程序博客网 时间:2024/05/19 21:03


import java.awt.*;

import javax.swing.*;


public class BorderLayoutDemo extends JFrame{


private static final long serialVersionUID = 1L;
private JPanel main,north,south,center,east,west;

private BorderLayoutDemo(){

main = new JPanel(new BorderLayout(10,10)); //水平和纵向间距设置
north = new JPanel();
south = new JPanel();
center = new JPanel();
east = new JPanel();
west = new JPanel();

this.setSize(600,600);
this.setVisible(true);
this.setLocation(300, 0);
this.add(main);
main.add(center);
main.add(east,BorderLayout.EAST);
main.add(north,BorderLayout.NORTH);
main.add(south,BorderLayout.SOUTH);
main.add(west,BorderLayout.WEST);

north.setBackground(Color.RED); //面板颜色设置
south.setBackground(Color.PINK);
east.setBackground(Color.GREEN);
west.setBackground(Color.CYAN);
center.setBackground(Color.YELLOW);

}


public static void main(String[] args) {
new BorderLayoutDemo();


}


}
0 0
原创粉丝点击