如果想要出现按钮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. 后台数据导出为Excel

    数据导出的方法如下: 一.下载office的类库:microsoft.office.interop.excel.zip 根据电脑安装的office版本选择引入相应的类库,office2007选择12. ...

  2. MVC Razor视图引擎

    Razor 不是编程语言.它是服务器端标记语言. Razor 是一种允许您向网页中嵌入基于服务器的代码(Visual Basic 和 C#)的标记语法 当网页被写入浏览器时,基于服务器的代码能够创建动 ...

  3. UDP通讯协议

    常见的通讯协议有udp和tcp. 先来简单了解一下这两个协议各自的特点: UDP: --将数据及源.目的封装在数据包中,不需要建立连接: --每个数据包的大小限制在64k以内: --因无连接,是不可靠 ...

  4. Linux环境 Mysql新建用户和数据库并授权

    测试环境:linux 和Mysql 5.5.35 一.新建用户 //登录Mysql@>mysql -u root -p@>密码//创建用户mysql> insert into mys ...

  5. 跨域资源共享 CORS 详解

    CORS是一个W3C标准,全称是"跨域资源共享"(Cross-origin resource sharing). 它允许浏览器向跨源服务器,发出XMLHttpRequest请求,从 ...

  6. flexible.js字体大小诡异现象解析及解决方案

    最近在做一个手机端页面时,遇到了一个奇怪的问题:字体的显示大小,与在CSS中指定的大小不一致.大家可以查看这个Demo(记得打开Chrome DevTools). 就如上图所示,你可以发现,原本指定的 ...

  7. 解决ERROR 2006 (HY000): MySQL server has gone away

    刚把博客从百度云搬到腾讯云,发现文章少了几篇.当时在导入dump数据的时候,就曾经发现mysql提示: ERROR 2006 (HY000): MySQL server has gone away N ...

  8. Chrome开发者工具详解(3):Timeline面板

    Timeline面板 Timeline面板是整个面板里面最复杂的一个面板,涉及的东西比较多.可以利用这个面板来记录和分析网页运行过程中的所有活动行为信息. 你可以充分利用这个面板来分析你的网页的程序性 ...

  9. 模板页 相对路径 JS 加载问题

    问题:我在master页面中引入了如下js文件:<script type="text/javascript" src="http://www.cnblogs.com ...

  10. Dapper simplecrud的使用

    为了方便Dapper操作可以使用Dapper的相关扩展dapper simplecrud. 1.首先点击管理NuGet