Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1698257
  • 博文数量: 210
  • 博客积分: 10013
  • 博客等级: 上将
  • 技术积分: 2322
  • 用 户 组: 普通用户
  • 注册时间: 2008-09-25 15:56
文章分类

全部博文(210)

文章存档

2011年(34)

2010年(121)

2009年(37)

2008年(18)

我的朋友

分类: Java

2011-03-15 14:12:57

package com.utstar.factory;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
/**
 * FlowLayout按照添加控件的顺序按行来添加,默认中间对齐,可以在创建flowlayout的时候设定对其方式
 * 一行放不下放第二行
 * @author HZ20232
 *
 */

public class TestFlowLayout extends JFrame{
    private static final long serialVersionUID = 6819222900970457455L;
    private JButton button1;
    private JButton button2;
    private JButton button3;
    private JButton button4;
    private JButton button5;
    private JButton button6;
    private JPanel panel;
    public TestFlowLayout(){
        this.setSize(new Dimension(400,400));
        this.setTitle("测试");
        init();
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setVisible(true);
    }
    private void init(){
        button1 = new JButton("NORTH");
        button2 = new JButton("SOUTH");
        button3 = new JButton("EAST");
        button4 = new JButton("WEST");
        button5 = new JButton("CENTER");
        button6 = new JButton("CENTER6");
        panel = new JPanel();
        FlowLayout myLayout = new FlowLayout(FlowLayout.LEFT);
//        FlowLayout myLayout = new FlowLayout(FlowLayout.RIGHT);

//        FlowLayout myLayout = new FlowLayout(FlowLayout.CENTER);

//        FlowLayout myLayout = new FlowLayout(FlowLayout.LEADING);

//        FlowLayout myLayout = new FlowLayout(FlowLayout.TRAILING);

        this.setLayout(myLayout);
        this.add(button1);
        this.add(button2);
        this.add(button3);
        this.add(button4);
        this.add(button5);
        this.add(button6);
    }
    public static void main(String args[]){
        TestFlowLayout test = new TestFlowLayout();
    }
}


阅读(5937) | 评论(1) | 转发(0) |
给主人留下些什么吧!~~

chinaunix网友2011-03-27 13:27:12

很好的, 收藏了 推荐一个博客,提供很多免费软件编程电子书下载: http://free-ebooks.appspot.com