GridBagLayout占多行效果注意

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

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


 1 package com.wst.bj;
 2
 3 import java.awt.GridBagConstraints;
 4 import java.awt.GridBagLayout;
 5
 6 import javax.swing.JButton;
 7 import javax.swing.JFrame;
 8
 9 class GridBagText {
10
11     JFrame jframe = new JFrame("搜索");
12
13     JButton jButton = new JButton("按钮1");
14     JButton jButton2 = new JButton("按钮2");
15     JButton jButton3 = new JButton("按钮3");
16     JButton jButton4 = new JButton("按钮4");
17
18     public GridBagText() {
19
20         init();
21     }
22
23     private void init()
24     {
25         FrameUtil.initFram(jframe, 500, 700);
26
27         GridBagLayout gridBagLayout = new GridBagLayout();
28         jframe.setLayout(gridBagLayout);
29         GridBagConstraints constraints = new  GridBagConstraints();
30
31         constraints.fill = GridBagConstraints.BOTH;
32         constraints.weightx = 1.0;
33         constraints.weighty = 1.0;
34
35
36         constraints.gridheight = 1;
37         constraints.gridwidth = GridBagConstraints.REMAINDER;
38         gridBagLayout.setConstraints(jButton, constraints);
39         jframe.add(jButton);
40
41         constraints.gridheight = 2;
42         constraints.gridwidth = 1;
43         gridBagLayout.setConstraints(jButton2, constraints);
44         jframe.add(jButton2);
45
46         constraints.gridheight = 1;
47         constraints.gridwidth = GridBagConstraints.REMAINDER;
48         gridBagLayout.setConstraints(jButton3, constraints);
49         jframe.add(jButton3);
50         gridBagLayout.setConstraints(jButton4, constraints);
51         jframe.add(jButton4);
52
53
54         jframe.setSize(jframe.getPreferredSize());
55         jframe.setVisible(true);
56 //        jframe.pack();
57     }
58 }


 1 package com.wst.bj;
 2
 3 import java.awt.GridBagConstraints;
 4 import java.awt.GridBagLayout;
 5
 6 import javax.swing.JButton;
 7 import javax.swing.JFrame;
 8
 9 class GridBagText {
10
11     JFrame jframe = new JFrame("搜索");
12
13     JButton jButton = new JButton("按钮1");
14     JButton jButton2 = new JButton("按钮2");
15     JButton jButton3 = new JButton("按钮3");
16 //    JButton jButton4 = new JButton("按钮4");
17
18     public GridBagText() {
19
20         init();
21     }
22
23     private void init()
24     {
25         FrameUtil.initFram(jframe, 500, 700);
26
27         GridBagLayout gridBagLayout = new GridBagLayout();
28         jframe.setLayout(gridBagLayout);
29         GridBagConstraints constraints = new  GridBagConstraints();
30
31         constraints.fill = GridBagConstraints.BOTH;
32         constraints.weightx = 1.0;
33         constraints.weighty = 1.0;
34
35
36         constraints.gridheight = 1;
37         constraints.gridwidth = GridBagConstraints.REMAINDER;
38         gridBagLayout.setConstraints(jButton, constraints);
39         jframe.add(jButton);
40
41         constraints.gridheight = 2;
42         constraints.gridwidth = 1;
43         gridBagLayout.setConstraints(jButton2, constraints);
44         jframe.add(jButton2);
45
46         constraints.gridheight = 1;
47         constraints.gridwidth = GridBagConstraints.REMAINDER;
48         gridBagLayout.setConstraints(jButton3, constraints);
49         jframe.add(jButton3);
50 //        gridBagLayout.setConstraints(jButton4, constraints);
51 //        jframe.add(jButton4);
52
53
54         jframe.setSize(jframe.getPreferredSize());
55         jframe.setVisible(true);
56 //        jframe.pack();
57     }
58 }


 1 package com.wst.bj;
 2
 3 import java.awt.GridBagConstraints;
 4 import java.awt.GridBagLayout;
 5
 6 import javax.swing.JButton;
 7 import javax.swing.JFrame;
 8
 9 class GridBagText {
10
11     JFrame jframe = new JFrame("搜索");
12
13     JButton jButton = new JButton("按钮1");
14     JButton jButton2 = new JButton("按钮2");
15 //    JButton jButton3 = new JButton("按钮3");
16 //    JButton jButton4 = new JButton("按钮4");
17
18     public GridBagText() {
19
20         init();
21     }
22
23     private void init()
24     {
25         FrameUtil.initFram(jframe, 500, 700);
26
27         GridBagLayout gridBagLayout = new GridBagLayout();
28         jframe.setLayout(gridBagLayout);
29         GridBagConstraints constraints = new  GridBagConstraints();
30
31         constraints.fill = GridBagConstraints.BOTH;
32         constraints.weightx = 1.0;
33         constraints.weighty = 1.0;
34
35
36         constraints.gridheight = 1;
37         constraints.gridwidth = GridBagConstraints.REMAINDER;
38         gridBagLayout.setConstraints(jButton, constraints);
39         jframe.add(jButton);
40
41         constraints.gridheight = 2;
42         constraints.gridwidth = 1;
43         gridBagLayout.setConstraints(jButton2, constraints);
44         jframe.add(jButton2);
45
46 //        constraints.gridheight = 2;
47 //        constraints.gridwidth = GridBagConstraints.REMAINDER;
48 //        gridBagLayout.setConstraints(jButton3, constraints);
49 //        jframe.add(jButton3);
50 //        gridBagLayout.setConstraints(jButton4, constraints);
51 //        jframe.add(jButton4);
52
53
54         jframe.setSize(jframe.getPreferredSize());
55         jframe.setVisible(true);
56 //        jframe.pack();
57     }
58 }
时间: 2024-10-08 10:27:59

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

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

//查询所有表名 select name from sysobjects where xtype='u'SELECT     name, object_id, principal_id, schema_id, parent_object_id, type, type_desc, create_date, modify_date, is_ms_shipped, is_published,                       is_schema_published, lob_data_spa

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

VBA取得EXCEL表格中的行数和列数 初学EXCEL宏的童鞋,总是很想知道表格中含有数据的行数和列数,尤其是行数和列数不确定的情况下.这样可以避免很多的错误,并且可以提高效率.但每次用到的时候到网上查找时,总是给了很多无用的答案,往往找不到想要的结果.笔者也是每次使用时,临时查找总是很头疼.偶然发现一篇博客,上面详细记录了不同的方法,笔者测试了几种发现真的很好用.本着分享万岁的精神,将博客内容共享出来.希望对大家有所帮助. 来源:http://www.okexcel.com.cn/bbs/vi

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

用VBA计算WPS 表格ET EXCEL中的行数和列数 每种方法中上面的是Excel的行数,下面的是Excel的列数. 方法1: ActiveSheet.UsedRange.Rows.Count ActiveSheet.UsedRange.Columns.Count 缺点:有时可能会比实际数大一些,原因是如果你把最后几行(列)数据清除后(非整行或整列删除), 用这个命令仍返回未清除前的值.就是说现在虽然是空的,但是你曾经用过也算你的. 方法2: ActiveSheet.Range("A65535

CSS3布局之flex布局效果

<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>Document</title> <style type="text/css"> *{ margin: 0; padding: 0; } .container{ width: 1000px; margin:0 auto; } he

jquery动态插入行,不用拼写html,简洁版

这个一个利用jquery实现动态插入输入行效果小功能,不用在javascript里拼写html字符串,更简洁.高效. html代码: <div class="fitem"> <table id="tblData"> <tr> <td>保证人姓名</td> <td>证件号码</td> <td>工作单位</td> <td>职务</td> &

sqlserver查询数据的所有表名和行数

原文:sqlserver查询数据的所有表名和行数 //查询所有表明select name from sysobjects where xtype='u' select * from sys.tables //查询数据库中所有的表名及行数 SELECT a.name AS [TABLE NAME] , b.rows AS [RECORD COUNT] FROM sysobjects AS a INNER JOIN sysindexes AS b ON a.id = b.id WHERE ( a.t

[C#小程序]命令行小程序之你要买大杯小杯还是中杯?

实现效果: 屏幕出现提示:1.小杯3元:2.中杯4元:3.大杯5元,请输入对应数字选择... 用户输入数字则提示对应的结果:小杯,请支付3元:输入错误则默认中杯 下面是源代码: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleManyHellos {     class Progr

ie6,7折行问题

html <div class="left"> <div class="channel clearfix"> <span>品牌营销</span> <div class="content"> <a>品牌曝光</a> <a>品牌互动</a> <a>品牌辨析</a> <a>决策工具</a> <

VB.NET中自定义GridView的多行复合表头

我们都知道单行表头的合并是很好实现的,只需室友横跨列的ColumnSpan属性就可以实现, 但是在开发中,经常遇到表格的多行复合表头设计的问题,怎么扩展GridView控件以实现多行表头呢? ­要点:先定义第一行各占多少行,多少列,再追加第二行,以此类推 主体思路是这样的,GridView在ASP.NET中最终是转化为html的表格格式来显示的,所以我们要在其中做点文章, 看下面这段代码: 1 ''' <summary> 2 ''' 画面レイアウトより.GridViewのヘッダを設定 3 ''