2019年09月18日(星期三)  农历:己亥年八月二十

作者:三年。分类: JAVA

FloswLayout是每个JPanel对象的默认布局管理器,它就是按照顺序行云流水般的把所有的组件一个一个的画上去。例子很简单

在CODE上查看代码片派生到我的代码片

/*

* BoxLayoutDemo.java requires no other files.

*/

import java.awt.Component;

import java.awt.ComponentOrientation;

import java.awt.Container;

import java.awt.FlowLayout;

import javax.swing.BoxLayout;

import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.JPanel;

public class BoxLayouts extends JFrame{

private JButton btn1 = new JButton("Button1");

private JButton btn2 = new JButton("Button2");

private JButton btn3 = new JButton("Button3 what a fine day");

private JButton btn4 = new JButton("Button4 what a fine da");

private JButton btn5 = new JButton("Button5 what a fine d");

private JButton btn6 = new JButton("Button6 what a fines");

private JButton btn7 = new JButton("Button7");

private JButton btn8 = new JButton("Button8");

private JButton btn9 = new JButton("Button3 what a fine day");

private JButton btn10 = new JButton("Button4 what a fine da");

private JButton btn11 = new JButton("Button5 what a fine d");

private JButton btn12 = new JButton("Button6 what a fines");

BoxLayouts()

{

super();

initComponent();

}

private void initComponent()

{

Container container = this.getContentPane();

//container.setLayout(new BoxLayout(container,BoxLayout.LINE_AXIS));

container.setLayout(new FlowLayout());

container.add(btn1);

container.add(btn2);

container.add(btn3);

container.add(btn4);

container.add(btn5);

container.add(btn6);

container.add(btn7);

container.add(btn8);

container.add(btn9);

container.add(btn10);

container.add(btn11);

container.add(btn12);

}

public static void main(String[] args)

{

BoxLayouts frame = new BoxLayouts();

frame.pack();

frame.setVisible(true);

}

}

程序运行结果:

温馨提示如有转载或引用以上内容之必要,敬请将本文链接作为出处标注,谢谢合作!

已有 0/1497 人参与

发表评论:



手Q扫描加入Java初学者群