如何用flowlayout对界面进行布局

如题所述

第1个回答  2016-12-09
Flowlayout布局是流布局,意思就是说从左上角开始添加原件,
一次往后排,第一行挤满了就换一行接着排。

也就是说,无法手动控制换行,流布局提供一些几种流排布方式:

FlowLayout.LEFT:左对齐
FlowLayout.RIGHT :右对齐
FlowLayout.CENTER :居中
FlowLayout.LEADING :父容器依赖左对齐
FlowLayout.TRAILING:父容器依赖右对齐

使用方法为:

FloatLayout layout = new FlowLayout(布局方式, 水平间距, 垂直间距) ;

layout.setAlignment(FlowLayout.xxxx);

每一种你都试试吧。

使用setBounds()可以直接把组件放到容器的指定位置上。
但是要求容器为空布局,换句话说,你直接:
JPanel p = new JPanel();
JFrame f = new JFrame();
f.add(p);
JButton b = new JButton("Button");
b.setBounds(起点横坐标,起点纵坐标,元件宽,元件高);
p.add(b);
就ok了!本回答被提问者采纳
相似回答