JavaSwing布局FlowLayout的用法
来源:互联网 发布:初中网络课程 编辑:程序博客网 时间:2024/06/05 17:31
import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.*;
public class FlowLayoutDemo {
public FlowLayoutDemo(){
JFrame f = new JFrame();
Container contentPane = f.getContentPane();
contentPane.setLayout(new FlowLayout());
contentPane.add(new JButton("first"));
contentPane.add(new JButton("second"));
contentPane.add(new JButton("third"));
contentPane.add(new JButton("fourth"));
contentPane.add(new JButton("fifth"));
contentPane.add(new JButton("This is the last button"));
f.setTitle("FlowLayout");
f.setSize(getPreferredSize());//getPreferredSize()获取当前窗口大小
f.setVisible(true);
f.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
}
private Dimension getPreferredSize() {
// TODO Auto-generated method stub
return new Dimension(200,200);
}
public static void main(String[] args) {
// TODO Auto-generated method stub
FlowLayoutDemo b = new FlowLayoutDemo();
}
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.*;
public class FlowLayoutDemo {
public FlowLayoutDemo(){
JFrame f = new JFrame();
Container contentPane = f.getContentPane();
contentPane.setLayout(new FlowLayout());
contentPane.add(new JButton("first"));
contentPane.add(new JButton("second"));
contentPane.add(new JButton("third"));
contentPane.add(new JButton("fourth"));
contentPane.add(new JButton("fifth"));
contentPane.add(new JButton("This is the last button"));
f.setTitle("FlowLayout");
f.setSize(getPreferredSize());//getPreferredSize()获取当前窗口大小
f.setVisible(true);
f.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
}
private Dimension getPreferredSize() {
// TODO Auto-generated method stub
return new Dimension(200,200);
}
public static void main(String[] args) {
// TODO Auto-generated method stub
FlowLayoutDemo b = new FlowLayoutDemo();
}
}
构造函数:
FlowLayout() 建立一个新的FlowLayout,默认居中对齐,组件彼此有5单位的水平与垂直间距
FlowLayout(int align) 建立一个新的FlowLayout,可设置排列方式,组件彼此有5单位的水平与垂直间距
FlowLayout(int align,int hgap,int vgap) 此FlowLayout可设置排列方式与组件间距
五种排列方式:
CENTER,LEFT,RIGHT,LEADING,TRAILING
例:contentPane.setLayout(new FlowLayout(FlowLayout.LEFT));
0 0
- JavaSwing布局FlowLayout的用法
- JavaSwing布局BorderLayout的用法
- JavaSwing布局GridLayout的用法
- FlowLayout布局
- FlowLayout布局
- FlowLayout布局
- FlowLayout的布局组件的流向
- Flowlayout流式布局的使用步骤
- FlowLayout实现自定义的流式布局
- JAVASwing GridBagLayout 布局
- Android流式布局FlowLayout,一款针对Tag的布局
- Draw2d之FlowLayout布局
- swing布局---FlowLayout
- FlowLayout浮动布局
- FlowLayout布局管理器
- java 布局之FlowLayout
- 布局管理器FlowLayout
- FlowLayout流式布局
- js基础——图片切换实例
- Construct Binary Tree from Preorder and Inorder Traversal
- cocos2d-x 通过JNI实现c/c++和Android的java层函数互调
- (十)(2) Z-Stack中OSAL定时器事件触发流程分析
- 不带头节点的链表尾插法C++实现
- JavaSwing布局FlowLayout的用法
- 工作感悟
- IOS网络篇17之分段下载、断点续传解析
- CornerStone配置SVN
- curl 命令
- android-xBuild apk差分与合成,zip差分与合成,lua打包,apk打包,png/jpg图片压缩
- android打开各种文件(setDataAndType)
- 1继承
- 对HTML5至关重要的10个Javascript资源