java 在 GridBagLayout 中设置 columnWidth 和 rowHeight

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12444092/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 08:54:04  来源:igfitidea点击:

Setting columnWidth and rowHeight in GridBagLayout

javaswinglayoutgridbaglayout

提问by FirmView

How to set columnWidth and rowHeight in GridBagLayout? Is it gridWidth and gridHeight?

如何在 GridBagLayout 中设置 columnWidth 和 rowHeight?是 gridWidth 和 gridHeight 吗?

enter image description here

在此处输入图片说明

How this column Widths can be specified dyanmically?

如何动态指定此列的宽度?

回答by MadProgrammer

According to the JavaDocs

根据JavaDocs

gridheight

网格高度

Specifies the number of cells in a column for the component's display area. Use REMAINDER to specify that the component's display area will be from gridy to the last cell in the column. Use RELATIVE to specify that the component's display area will be from gridy to the next to the last one in its column.

gridheight should be a non-negative value and the default value is 1.

指定组件显示区域的列中的单元格数。使用 REMAINDER 指定组件的显示区域将从网格到列中的最后一个单元格。使用 RELATIVE 指定组件的显示区域将从网格到其列中最后一个的下一个。

gridheight 应该是一个非负值,默认值为 1。

gridwidth

网格宽度

Specifies the number of cells in a row for the component's display area. Use REMAINDER to specify that the component's display area will be from gridx to the last cell in the row. Use RELATIVE to specify that the component's display area will be from gridx to the next to the last one in its row.

gridwidth should be non-negative and the default value is 1.

为组件的显示区域指定一行中的单元格数。使用 REMAINDER 指定组件的显示区域将从 gridx 到行中的最后一个单元格。使用 RELATIVE 指定组件的显示区域将从 gridx 到其行中最后一个的下一个。

gridwidth 应为非负值,默认值为 1。

So, if you want to specify the number of rows or columns a component will span, then, yes

所以,如果你想指定一个组件将跨越的行数或列数,那么,是的

回答by basiljames

You cannot specify the widthand heightof a cell in GridBagLayout; if that is what you are looking to do. Th layout manager calculates row height based on all components in the row.

您不能在 GridBagLayout 中指定单元格的widthheight;如果这就是你想要做的。布局管理器根据行中的所有组件计算行高。

You can check this Oracle tutorial on GridBagLayout

您可以在 GridBagLayout 上查看此Oracle 教程

AddedBased on the screen shot you added seems you are using some tool like JFormDesigner. It is a customised layout, column width and column height does not come in standard GridBagLayout.

添加根据您添加的屏幕截图,您似乎正在使用 JFormDesigner 之类的工具。它是自定义布局,列宽和列高不在标准 GridBagLayout 中。