GridBagLayout占多行效果注意
如果想要出现按钮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占多行效果注意的更多相关文章
- linkbutton datagrid showdialog 行效果
protected void DataGrid1_ItemDataBound(object sender, DataGridItemEventArgs e) { ListItemType itemTy ...
- SQL Server查询所有的表名/空间占用量/行数
select object_name(id) tablename, 8*reserved/1024 reserved, rtrim(8*dpages)+'kb' used, 8*(reserved-d ...
- android TextView字体设置最少占多少行. 及其 Java String 字符串操作 . .
① 字体设置: 修改代码 : GridViewActivity.java priceTv为 TextView priceTv.setMaxLines(3); //当多与7个字fu的时候 , 其余字 ...
- sqlserver查询数据的所有表名和行数及空间占用量
//查询所有表名 select name from sysobjects where xtype='u' --modify_date指表结构最后更新日期,并非数据最后更新日期SELECT na ...
- webpages框架中使用Html.TextArea()在前台显示多行信息时,如何进行大小、样式的设置
环境:vs2015 webpages框架+razor语法: 目的:服务器进行数据更新操作后,在前台显示更新的相关信息: 后台代码:将更新条数等相关信息存储在一个变量中: @{ var serverIn ...
- 用VBA计算WPS 表格ET EXCEL中的行数和列数的多重方法
用VBA计算WPS 表格ET EXCEL中的行数和列数 每种方法中上面的是Excel的行数,下面的是Excel的列数. 方法1: ActiveSheet.UsedRange.Rows.Count Ac ...
- VBA取得EXCEL表格中的行数和列数
VBA取得EXCEL表格中的行数和列数 初学EXCEL宏的童鞋,总是很想知道表格中含有数据的行数和列数,尤其是行数和列数不确定的情况下.这样可以避免很多的错误,并且可以提高效率.但每次用到的时候到网上 ...
- C# 得到EXCEL表格中的有效行数和列数
每种方法中上面的是Excel的行数,下面的是Excel的列数.方法七:经过加工修改已经可以读出来的是有效数据行 using Excel = Microsoft.Office.Interop.Excel ...
- Office EXCEL VBA如何取得EXCEL中的行数和列数
VBA取得EXCEL表格中的行数和列数 请注意不要使用Columus等关键字作为变量,例如"Columus = ActiveSheet.UsedRange.Columns.Count&quo ...
随机推荐
- python学习之路-8 面向对象之进阶
上篇内容回顾和补充 面向对象三大特性 封装 继承 多态 在python中没有多态的概念 变量的类型允许为多种数据类型称之为多态 # c#/java中的多态 # 伪代码 def func(int arg ...
- DIV + CSS 盒子模型
盒子模型有两种,分别是 IE 盒子模型和标准 W3C 盒子模型.他们对盒子模型的解释各不相同, 先来看看我们熟悉的标准盒子模型: 图片看不清楚?请点击这里查看原图(大图). 从上图可以看到标准 W3C ...
- [HDU 1535]Invitation Cards[SPFA反向思维]
题意: (欧洲人自己写的题面就是不一样啊...各种吐槽...果断还是看晕了) 有向图, 有个源叫CCS, 求从CCS到其他所有点的最短路之和, 以及从其他所有点到CCS的最短路之和. 思路: 返回的时 ...
- java编程排错技巧
一.Eclipse提示错误The type java.lang.CharSequence cannot be resolved. It is indirectly referenced from re ...
- iOS新的旅程之Swift语言的学习
好久都没有来这个熟悉而又陌生的地方啦, 想想已经有两三个月了吧,不过我相信以后还是会经常来的啦,因为忙碌的学习已经过去啦,剩下的就是要好好的总结好好的复习了,好好的熟悉下我们之前学习的知识点,将他们有 ...
- 一个Demo就懂的Angular之directive
<body> <div ng-controller="myCtrl"> <hello-word></hello-word> < ...
- js中的eval方法转换对象时,为何一定要加上括号?
待转换的是一个Json字符串: {'name':'新欢'} 而使用如下这种方式调用则会抛出语法异常, eval("{'name':'新欢'}"); 必须加上括号才行 eval(&q ...
- React-Native OpenGL体验一
昨天初体验了一把SVG一个并不是多么复杂的动画,我在iOS模拟器上体验的是流畅的,但是在Android真机上体验,还是比较卡的. 下面来介绍一个OpenGL的第三方库: 下面是我运行的里面Demo的效 ...
- U盘制作Linux系统盘
一.首先需要有一个U盘,最好能是8G及以上的 二.下载Linux的镜像文件(我这边安装的是red hat6.3) 下载路径:http://pan.baidu.com/s/1jIGYCKI 三.下载制作 ...
- c3p0连接数据库
<?xml version="1.0" encoding="UTF-8"?> <c3p0-config> <default-con ...