JavaSwing布局管理器示例

2012-11-12

    package com.utstar.factory;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    /**
    * GridLayout布局管理器是设定行*列的布局,中途可以增加行或列数,按照添加控件的顺序从左至右从上至下来添加
    * 可以设定整体行列之间的间隔,不能跨行跨列,适用于控件布局类似棋盘的样式。
    * @author HZ20232
    *
    */
    public class TestGridLayout 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;
    public TestGridLayout(){
    this.setSize(600,400);
    this.setTitle("测试");
    init();
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    this.setVisible(true);
    }
    public 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");
    GridLayout myLayout = new GridLayout(2,3);
    myLayout.setHgap(10);
    myLayout.setVgap(10);
    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[]){
    TestGridLayout test = new TestGridLayout();
    }
    }

  考试大温馨提示:本内容来源于网络,仅代表作者个人观点,与本站立场无关,仅供您学习交流使用。其中可能有部分文章经过多次转载而造成文章内容缺失、错误或文章作者不详等问题,请您谅解。如有侵犯您的权利,请联系我们,本站会立即予以处理。

分享到:
0
相关阅读
友情链接
© 2018 我考网 http://www.woexam.com 中国互联网举报中心 湘ICP备18023104号 京公网安备 11010802020116号
违法和不良信息举报:9447029@qq.com