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 ...
随机推荐
- 【转】PF_NETLINK应用实例NETLINK_KOBJECT_UEVENT具体实现--udev实现原理
相对于linux来说,udev还是一个新事物.然而,尽管它03年才出现,尽管它很低调(J),但它无疑已经成为linux下不可或缺的组件了.udev是什么?它是如何实现的?最近研究Linux设备管理时, ...
- hdu 5256 序列变换(LIS最长上升子序列)
Problem Description 我们有一个数列A1,A2...An,你现在要求修改数量最少的元素,使得这个数列严格递增.其中无论是修改前还是修改后,每个元素都必须是整数. 请输出最少需要修改多 ...
- 计算直线的交点数(set + 打表)
计算直线的交点数 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total S ...
- Android UI布局之FrameLayout
一个FrameLayout对象就好比一块屏幕上提前预定好的空白区域.然后能够填充一些元素到里边.例如说一张图片等.须要注意的是,全部的元素都被放置在FrameLayout区域最左边上的区域.并且无法为 ...
- Impala与Hive的比較
1. Impala架构 Impala是Cloudera在受到Google的Dremel启示下开发的实时交互SQL大数据查询工具,Impala没有再使用缓慢的Hive+MapReduce批 ...
- [ReactJS] DOM Event Listeners in a React Component
React doesn't provide the listener to listen the DOM event. But we can do it in React life cycle: So ...
- html5的a标签使用
主要是href和target两个属性 示比例如以下: <a href="" target="_blank">Visit w3school</a ...
- 改变navigationbar的底部线条颜色
[[UINavigationBar appearance] setBackgroundImage:[UIImage new]forBarMetrics:UIBarMetricsDefault]; CG ...
- Wordpress更换主题之后出错
今天吃完午饭,休息休息,最近搞了一下google adsense,不过最终的审核没通过,我想会不会是界面不好看呢,饭后就在电脑旁,更换了几个wordpress主题,我的博客使用wordpress搭建的 ...
- user密码
一.修改密码 alter user hr identified by hr; password/passw hr: SYS@test>password hr Changing password ...