java的gui界面布局_java进阶10 GUI图形界面 布局管理器之FlowLayout GridLayout

先说说FlowLayout

流式布局管理器。

效果

D+shaAWBtOV3wAAAABJRU5ErkJggg==

这是当第一行显示不下,才转到第二行的。

看看代码

packageFrame;importjava.awt.BorderLayout;importjava.awt.FlowLayout;importjavax.swing.JButton;importjavax.swing.JFrame;public classMyLayout{

JFrame frame;publicMyLayout(JFrame frame) {//TODO Auto-generated constructor stub

this.frame=frame;

}//留给UI类操作的函数

public voidcreatLayout(){

ShowFlowLayout();

}voidShowFlowLayout(){

frame.setLayout(newFlowLayout());

JButton East=new JButton("东方");

JButton West=new JButton("西方");

JButton North=new JButton("北方");

JButton South=new JButton("南方");

JButton Center=new JButton("中央");

JButton East1=new JButton("东方1");

JButton West1=new JButton("西方1");

JButton North1=new JButton("北方1");

JButton South1=new JButton("南方1");

JButton Center1=new JButton("中央1");

frame.add(East);

frame.add(West);

frame.add(North);

frame.add(South);

frame.add(Center);

frame.add(East1);

frame.add(West1);

frame.add(North1);

frame.add(South1);

frame.add(Center1);

}

}

基本,处理BorderLayout 不用写setLayout()这个函数之外,其他布局都要写,系统默认的是流式布局。

其构造中还有其他方法

frame.setLayout(new FlowLayout(FlowLayout.LEFT));

效果:

dhC3qMtQe+rYi77uQAoHJT7+zfKeY+2BL2virns5wKgcFDuMsJc+UoHnxOACO2WOwAggyh3ABCIcgcAgSh3ABCIcgcAgSh3ABCIcgcAgSh3ABCIcgcAgSh3ABCIcgcAgSh3ABCIcgcAgSh3ABCIcgcAgSh3ABCIcgcAgSh3ABCIcgcAgSh3ABCIcgcAgSh3ABCIcgcAgSh3ABCIcgcAgSh3ABCIcgcAgSh3ABCIcgcAgSh3ABCIcgcAgSh3ABCIcgcAgSh3ABCIcgcAgSh3ABCIcgcAgSh3ABCIcgcAgSh3ABCIcgcAgSh3ABCIcgcAgSh3ABCIcgcAgSh3ABCIcgcAgSh3ABCIcgcAgSh3ABCIcgcAgSh3ABCIcgcAgSh3ABCIcgcAgSh3ABCIcgcAgSh3ABCIcgcAgSh3ABCIcgcAgSh3ABCIcgcAgSh3ABCIcgcAgSh3ABCIcgcAgSh3ABCIcgcAgSh3ABCIcgcAgSh3ABCIcgcAgSh3ABCIcgcAgSh3ABCIcgcAgSh3ABCIcgcAgSh3ABCIcgcAgSh3ABCIcgcAgSh3ABCIcgcAgSh3ABCIcgcAgSh3ABCIcgcAgSh3ABCIcgcAgSh3ABCIcgcAgSh3ABCIcgcAgSh3ABCIcgcAgSh3ABCIcgcAgSh3ABCIcgcAgSh3ABCIcgcAgSh3ABCIcgcAgSh3ABCIcgcAgSh3ABCIcgcAgSh3ABCIcgcAgSh3ABCIcgcAgSh3ABCIcgcAgSh3ABCIcgcAgSh3ABCIcgcAgSh3ABCIcgcAgSh3ABCIcgcAgSh3ABCIcgcAgSh3ABCIcgcAgSh3ABCIcgcAgSh3ABCIcgcAgSh3ABCIcgcAgSh3ABCIcgcAgSh3ABCIcgcAgSh3ABCIcgcAgSh3ABCIcgcAgSh3ABCIcgcAgSh3ABCIcgcAgVKXOyGEkFwkRbkTQgjJbyh3QggRGMqdEEIEhnInhBCBodwJIURgKHdCCBGYrXInhBAiLP8PsFSRRTV5vqEAAAAASUVORK5CYII=

其他的就不再演示了,可以自己去试下。

接下来在说说 GridLayout

网格布局

wER8WwepDaQdAAAAABJRU5ErkJggg==

其主要代码块

voidShowGridLayout(){

frame.setLayout(new GridLayout(3,3));

JButton East=new JButton("东方");

JButton West=new JButton("西方");

JButton North=new JButton("北方");

JButton South=new JButton("南方");

JButton Center=new JButton("中央");

JButton East1=new JButton("东方1");

JButton West1=new JButton("西方1");

JButton North1=new JButton("北方1");

JButton South1=new JButton("南方1");

frame.add(East);

frame.add(West);

frame.add(North);

frame.add(South);

frame.add(Center);

frame.add(East1);

frame.add(West1);

frame.add(North1);

frame.add(South1);

}

这里还可以设置各网格之间的间距。

Aa2Vzi26KBiIAAAAAElFTkSuQmCC

改下构造函数即可

frame.setLayout(new GridLayout(3,3,12,12));

关于这些布局都是很简单的说明。

一般各种复杂的布局,其实就是这三个布局的互相嵌套形成的。

只要会了这3个布局,基本任何界面都能做出来。

关于图形界面就不会再讲了

因为我的重点不在这里

主要是在java ee 和android上

个人对这个不是很重视。

关于其他控件之类的有时间再研究吧。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值