//网格布局管理器
import java.awt.*;
import javax.swing.*;
public class Jiemian3 extends JFrame{ //定义组件
JButton[] an = {null,null,null,null,null,null,null,null}; public static void main(String[] args){
//运行本类的构造方法
Jiemian3 jiemian = new Jiemian3(); } public Jiemian3(){ //创建按钮
an[0] = new JButton("话梅");
an[1] = new JButton("果铺");
an[2] = new JButton("薯片");
an[3] = new JButton("饼干");
an[4] = new JButton("巧克力");
an[5] = new JButton("腰果");
an[6] = new JButton("锅巴");
an[7] = new JButton("开心果"); //网格布局管理器声明
//第一个参数是行,第二个参数是列,第三个参数是横间距,第四个参数是竖间距
this.setLayout(new GridLayout(3,3,15,15)); //添加按钮
this.add(an[0]);
this.add(an[1]);
this.add(an[2]);
this.add(an[3]);
this.add(an[4]);
this.add(an[5]);
this.add(an[6]);
this.add(an[7]); //设置窗口标题
this.setTitle("网格布局Gridlayout");
//设置窗口的宽高
this.setSize(300,300);
//设置窗口出现对于屏幕的位置
this.setLocation(100,100);
//禁止拉大拉小
this.setResizable(false);
//关闭窗口后释放资源
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//输出窗口
this.setVisible(true);
} }

//网格布局管理器import java.awt.*;import javax.swing.*;public class Jiemian3 extends JFrame{//定义组件JButton[]an={null,null,null,null,null,null,null,null};public static void main(String[] args){//运行本类的构造方法Jiemian3 jiemian=new Jiemian3();}public Jiemian3(){//创建按钮an[0]=new JButton("话梅");an[1]=new JButton("果铺");an[2]=new JButton("薯片");an[3]=new JButton("饼干");an[4]=new JButton("巧克力");an[5]=new JButton("腰果");an[6]=new JButton("锅巴");an[7]=new JButton("开心果");//网格布局管理器声明//第一个参数是行,第二个参数是列,第三个参数是横间距,第四个参数是竖间距this.setLayout(new GridLayout(3,3,15,15));//添加按钮this.add(an[0]);this.add(an[1]);this.add(an[2]);this.add(an[3]);this.add(an[4]);this.add(an[5]);this.add(an[6]);this.add(an[7]);//设置窗口标题this.setTitle("网格布局Gridlayout");//设置窗口的宽高this.setSize(300,300);//设置窗口出现对于屏幕的位置this.setLocation(100,100);//禁止拉大拉小this.setResizable(false);//关闭窗口后释放资源this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//输出窗口this.setVisible(true);}}

JAVA 网格布局管理器的更多相关文章

  1. java网格布局管理器

    public class GirdLayoutPosition extends JFrame{    public GirdLayoutPosition()    {        Container ...

  2. Java基础之创建窗口——使用网格布局管理器(TryGridLayout)

    控制台程序. 网格布局管理器可以在容器的矩形网格中布局组件. import javax.swing.*; import java.awt.*; import javax.swing.border.Et ...

  3. JAVA简单的网格布局管理器--JAVA基础

    网格布局管理器: GridLayoutDemo.java: import java.awt.GridLayout;import javax.swing.JButton;import javax.swi ...

  4. 编写Java程序,将JButton按钮按网格布局管理器格式放置

    返回本章节 返回作业目录 需求说明: 将JButton按钮按网格布局管理器格式放置 实现思路: 实现代码: public void init(){ setLayout(new GridLayout(4 ...

  5. java基础 布局管理器

    概念: 组建在容器(比如JFrame)中的位置和 大小 是由布局管理器来决定的.所有的容器都会使用一个布局管理器,通过它来自动进行组建的布局管理. 种类: java共提供了物种布局管理器:流式布局管理 ...

  6. JAVA GUI布局管理器

    边界布局管理器: a.布局方式:是把整个容器划分为五个部分.东西南北中,南北要贯通,中间最大 (不仅是中间的范围最大,权利也最大)当周边不存在的时候中间会占领周边,当中间不存在的时候周边不能占据中间 ...

  7. python之tkinter使用-Grid(网格)布局管理器

    # 使用tkinter编写登录窗口 # Grid(网格)布局管理器会将控件放置到一个二维的表格里,主控件被分割为一系列的行和列 # stricky设置对齐方式,参数N/S/W/E分别表示上.下.左.右 ...

  8. Java 的布局管理器GridBagLayout的使用方法(转)

    GridBagLayout是java里面最重要的布局管理器之一,可以做出很复杂的布局,可以说GridBagLayout是必须要学好的的, GridBagLayout 类是一个灵活的布局管理器,它不要求 ...

  9. 5、Java Swing布局管理器(FlowLayout、BorderLayout、CardLayout、BoxLayout、GirdBagLayout 和 GirdLayout)

    5.Java-Swing常用布局管理器       应用布局管理器都属于相对布局,各组件位置可随界面大小而相应改变,不变的只是其相对位置,布局管理器比较难以控制,一般只在界面大小需要改是才用,但即使这 ...

随机推荐

  1. 转(JSONP处理跨域事件)

     前言: 由于Sencha Touch 2这种开发模式的特性,基本决定了它原生的数据交互行为几乎只能通过AJAX来实现. 当然了,通过调用强大的PhoneGap插件然后打包,你可以实现100%的Soc ...

  2. PHP使用libevent实现高性能httpServer

    今天发现php也有一个libevent的扩展,安装后尝试下了一个webserver(httpserver), 发现性能还不错,逻辑很简单,每秒响应速度1800~4000次/s 代码如下 <?ph ...

  3. 【转】Winform 去掉 最大化 最小化 关闭按钮(不是关闭按钮变灰)终极解决办法

    不墨迹, 如图 : 网上 看了,好多 给的 答案 乱码七糟,都是扯淡,于是乎 自己 写,代码如下:窗体的大小暂时设置为:(598, 362) 涂红的数据根据你的窗体大小改动 using System; ...

  4. firefox不支持background-position-x background-position-y,使用background-position:5px 5px;

    firefox不支持background-position-x background-position-y,使用background-position:5px 5px;

  5. 使用druid连接池的超时回收机制排查连接泄露问题

    在工程中使用了druid连接池,运行一段时间后系统出现异常: Caused by: org.springframework.jdbc.CannotGetJdbcConnectionException: ...

  6. 如何破解海蜘蛛ISP6.1.5 极其isp运营商 v6.1.5

    海蜘蛛ISPV6.1.5,目前破解版本中最稳定的!破解步骤如下:一.安装完毕进控制台二.使用muddyboot登陆 密码(123456)三.输入root回车四.输入regtools回车五.在web控制 ...

  7. spring的ResultSetWrappingSqlRowSet使用rs.getTimestamp取oracle数据库时分秒问题

    oracle 11G数据库使用ojdbc14.jar驱动 rs.getTimestamp取不出时分秒问题: ResultSetWrappingSqlRowSet rs = processDao.que ...

  8. selenium+python自动化之环境安装

    一.Python安装 1.操作系统:win7 64位系统 2.下载Python安装包,选择2.7版本和3.6版本都可以(最好安装2.7版本稳定)官网下载地址:https://www.python.or ...

  9. CSS 使用小结

    1.文字过长显示省略号(....)  white-space: nowrap;overflow: hidden;text-overflow: ellipsis; 2.获取当前的ID : <asp ...

  10. Android 抽屉类SlidingDrawer的使用

     比较简单,设置好SlidingDrawer控件的handle和content属性就可以了.  android:content="@+id/content"  android:ha ...