如果想要出现按钮2占两行的效果,必须按键3、按钮4同时存在且同时可见。

  • 如果缺少按钮4,则按钮2不会占两行;
  • 如果缺少按钮3、4,则按钮2也不会占两行。

 package com.wst.bj;

 import java.awt.GridBagConstraints;
import java.awt.GridBagLayout; import javax.swing.JButton;
import javax.swing.JFrame; class GridBagText { JFrame jframe = new JFrame("搜索"); JButton jButton = new JButton("按钮1");
JButton jButton2 = new JButton("按钮2");
JButton jButton3 = new JButton("按钮3");
JButton jButton4 = new JButton("按钮4"); public GridBagText() { init();
} private void init()
{
FrameUtil.initFram(jframe, 500, 700); GridBagLayout gridBagLayout = new GridBagLayout();
jframe.setLayout(gridBagLayout);
GridBagConstraints constraints = new GridBagConstraints(); constraints.fill = GridBagConstraints.BOTH;
constraints.weightx = 1.0;
constraints.weighty = 1.0; constraints.gridheight = 1;
constraints.gridwidth = GridBagConstraints.REMAINDER;
gridBagLayout.setConstraints(jButton, constraints);
jframe.add(jButton); constraints.gridheight = 2;
constraints.gridwidth = 1;
gridBagLayout.setConstraints(jButton2, constraints);
jframe.add(jButton2); constraints.gridheight = 1;
constraints.gridwidth = GridBagConstraints.REMAINDER;
gridBagLayout.setConstraints(jButton3, constraints);
jframe.add(jButton3);
gridBagLayout.setConstraints(jButton4, constraints);
jframe.add(jButton4); jframe.setSize(jframe.getPreferredSize());
jframe.setVisible(true);
// jframe.pack();
}
}

 package com.wst.bj;

 import java.awt.GridBagConstraints;
import java.awt.GridBagLayout; import javax.swing.JButton;
import javax.swing.JFrame; class GridBagText { JFrame jframe = new JFrame("搜索"); JButton jButton = new JButton("按钮1");
JButton jButton2 = new JButton("按钮2");
JButton jButton3 = new JButton("按钮3");
// JButton jButton4 = new JButton("按钮4"); public GridBagText() { init();
} private void init()
{
FrameUtil.initFram(jframe, 500, 700); GridBagLayout gridBagLayout = new GridBagLayout();
jframe.setLayout(gridBagLayout);
GridBagConstraints constraints = new GridBagConstraints(); constraints.fill = GridBagConstraints.BOTH;
constraints.weightx = 1.0;
constraints.weighty = 1.0; constraints.gridheight = 1;
constraints.gridwidth = GridBagConstraints.REMAINDER;
gridBagLayout.setConstraints(jButton, constraints);
jframe.add(jButton); constraints.gridheight = 2;
constraints.gridwidth = 1;
gridBagLayout.setConstraints(jButton2, constraints);
jframe.add(jButton2); constraints.gridheight = 1;
constraints.gridwidth = GridBagConstraints.REMAINDER;
gridBagLayout.setConstraints(jButton3, constraints);
jframe.add(jButton3);
// gridBagLayout.setConstraints(jButton4, constraints);
// jframe.add(jButton4); jframe.setSize(jframe.getPreferredSize());
jframe.setVisible(true);
// jframe.pack();
}
}

 package com.wst.bj;

 import java.awt.GridBagConstraints;
import java.awt.GridBagLayout; import javax.swing.JButton;
import javax.swing.JFrame; class GridBagText { JFrame jframe = new JFrame("搜索"); JButton jButton = new JButton("按钮1");
JButton jButton2 = new JButton("按钮2");
// JButton jButton3 = new JButton("按钮3");
// JButton jButton4 = new JButton("按钮4"); public GridBagText() { init();
} private void init()
{
FrameUtil.initFram(jframe, 500, 700); GridBagLayout gridBagLayout = new GridBagLayout();
jframe.setLayout(gridBagLayout);
GridBagConstraints constraints = new GridBagConstraints(); constraints.fill = GridBagConstraints.BOTH;
constraints.weightx = 1.0;
constraints.weighty = 1.0; constraints.gridheight = 1;
constraints.gridwidth = GridBagConstraints.REMAINDER;
gridBagLayout.setConstraints(jButton, constraints);
jframe.add(jButton); constraints.gridheight = 2;
constraints.gridwidth = 1;
gridBagLayout.setConstraints(jButton2, constraints);
jframe.add(jButton2); // constraints.gridheight = 2;
// constraints.gridwidth = GridBagConstraints.REMAINDER;
// gridBagLayout.setConstraints(jButton3, constraints);
// jframe.add(jButton3);
// gridBagLayout.setConstraints(jButton4, constraints);
// jframe.add(jButton4); jframe.setSize(jframe.getPreferredSize());
jframe.setVisible(true);
// jframe.pack();
}
}

GridBagLayout占多行效果注意的更多相关文章

  1. linkbutton datagrid showdialog 行效果

    protected void DataGrid1_ItemDataBound(object sender, DataGridItemEventArgs e) { ListItemType itemTy ...

  2. SQL Server查询所有的表名/空间占用量/行数

    select object_name(id) tablename, 8*reserved/1024 reserved, rtrim(8*dpages)+'kb' used, 8*(reserved-d ...

  3. android TextView字体设置最少占多少行. 及其 Java String 字符串操作 . .

    ①  字体设置: 修改代码 :  GridViewActivity.java priceTv为 TextView priceTv.setMaxLines(3); //当多与7个字fu的时候 , 其余字 ...

  4. sqlserver查询数据的所有表名和行数及空间占用量

    //查询所有表名 select name from sysobjects where xtype='u' --modify_date指表结构最后更新日期,并非数据最后更新日期SELECT     na ...

  5. webpages框架中使用Html.TextArea()在前台显示多行信息时,如何进行大小、样式的设置

    环境:vs2015 webpages框架+razor语法: 目的:服务器进行数据更新操作后,在前台显示更新的相关信息: 后台代码:将更新条数等相关信息存储在一个变量中: @{ var serverIn ...

  6. 用VBA计算WPS 表格ET EXCEL中的行数和列数的多重方法

    用VBA计算WPS 表格ET EXCEL中的行数和列数 每种方法中上面的是Excel的行数,下面的是Excel的列数. 方法1: ActiveSheet.UsedRange.Rows.Count Ac ...

  7. VBA取得EXCEL表格中的行数和列数

    VBA取得EXCEL表格中的行数和列数 初学EXCEL宏的童鞋,总是很想知道表格中含有数据的行数和列数,尤其是行数和列数不确定的情况下.这样可以避免很多的错误,并且可以提高效率.但每次用到的时候到网上 ...

  8. C# 得到EXCEL表格中的有效行数和列数

    每种方法中上面的是Excel的行数,下面的是Excel的列数.方法七:经过加工修改已经可以读出来的是有效数据行 using Excel = Microsoft.Office.Interop.Excel ...

  9. Office EXCEL VBA如何取得EXCEL中的行数和列数

    VBA取得EXCEL表格中的行数和列数 请注意不要使用Columus等关键字作为变量,例如"Columus = ActiveSheet.UsedRange.Columns.Count&quo ...

随机推荐

  1. redis的简单使用

    一.简单使用Jedis 需要Jedis就从Maven获取吧! Maven Pom.xml <dependency> <groupId>redis.clients</gro ...

  2. (3)选择元素——(5)为项目列表加样式(Styling list-item levels)

    Let's suppose that we want the top-level items, and only the top-level items, to be arranged horizon ...

  3. Vlc for Android 全面阐述

    简单介绍 Vlc for android是一款开源安卓播放器.具备播放多媒体文件.光盘.设备以及网络流媒体协议等功能,支持ARMv7 CPU或一个x86 CPU的设备,全部播放控制特性都已经开发完整. ...

  4. 8. 冒泡法排序和快速排序(基于openCV)

    一.前言 主要讲述冒泡法排序和快速排序的基本流程,并给出代码实现,亲测可用. 二.冒泡法排序 冒泡法排序主要是将相邻两个值比较,把小的向前冒泡,大的向后沉淀,时间复杂度为O(n2).主要思想如下: 分 ...

  5. Java中随机数生成的两种方法,以及math的floor

    1.Math的random方法,调用这个Math.Random()函数能够返回带正号的double值,该值大于等于0.0且小于1.0,即取值范围是[0.0,1.0)的左闭右开区间,返回值是一个伪随机选 ...

  6. RMAN-FORMAT-CONFIGURE及动态性能表

    一.FORMAT参数在备份过程中,可指定format参数来自定义备份片段的命令规则,比如: RMAN> BACKUP DATABASE FORMAT 'D:\BACKUP\%U'; RMAN&g ...

  7. 无法登陆mysql服务器

    解决 .#2002 无法登录 MySQL 服务器 将config.sample.inc.php复制成config.inc.php 出现这个错误,表示没有连接到数据库.修改config.inc.php文 ...

  8. ASP.NET内核几大对象、ASP.NET核心知识(6)--转载

    这篇博文主要介绍一下几个对象. 1)HttpContext 2)HttpRequest 3)HttpResponse 4)context. Server 5)context.Session HttpC ...

  9. 【SQL学习笔记】排名开窗函数,聚合开窗函数(Over by)

    处理一些分组后,该组按照某列排序后 ,取其中某条完整数据的问题. 或 按照其中不同列分组后的聚合 比如 sum,avg之类. MSDN上语法: Ranking Window Functions < ...

  10. C# Datatable导出Excel方法

    C# 导出Excel方法  先引用下System.IO;System.data; 具体函数如下: public static bool ExportCSV(DataTable dt, string f ...