GridLayout 以及行数和列数
如果您没有完全填充 GridLayout,它是否会不遵守您指定的行数和列数?
我正在创建一个 3 行 4 列的 GridLayout。不过,我只添加了 9 个组件。它最终在 3x3 网格中向我显示这 9 个组件,而不是 3x4 网格(第三行只有 1 个组件(和两个空白))。
Does GridLayout ever not honor the number of rows and columns you've specified if you don't fill it completely?
I'm creating a GridLayout with 3 rows and 4 columns. However, I'm only adding 9 components. It ends up showing me these 9 components in a 3x3 grid, rather than a 3x4 grid (with only 1 component on the third row (and two blanks)).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
然后你应该使用以下方法创建 GridLayout:
它告诉布局你不知道有多少行,但你想要 4 列。因此,在移动到下一行之前,这些列将被填满。
不需要空组件。
Then you should be creating your GridLayout using:
It tell the layout that you don't know how many rows you have, but you want 4 columns. So the columns will be filled up before moving to the next row.
No need for empty components.
只需用空项目填充空单元格(例如
JLabel
),例如:这将它们布局为
Just fill empty cells with empty items (like a
JLabel
), eg:This layouts them as