有没有办法在GridBagLayout中设置固定的行和列?

时间:2021-10-12 09:10:56

I'm kinda new to GUI programming, and as I know, and as it shows, the GridBagLayout will merge empty rows or columns. My problem is that I have to add buttons on random positions, and it's not guaranteed that there's gonna be a button in every row or column, but I should keep the empty lines anyway.

我是GUI编程的新手,据我所知,并且如图所示,GridBagLayout将合并空行或列。我的问题是我必须在随机位置上添加按钮,并且不能保证每行或每列都会有一个按钮,但无论如何我应该保留空行。

I'm using GridBag cuz i have to change positions on some buttons and it seems handy for that.

我正在使用GridBag因为我必须改变一些按钮的位置,这似乎很方便。

So the question is: Is it possible to fix the rows and columns in a GridBagLayout? Or keep the empty lines somehow.

所以问题是:是否可以修复GridBagLayout中的行和列?或者以某种方式保留空行。

there is an example of the state of the buttons:

有一个按钮状态的例子:

Random Buttons

有没有办法在GridBagLayout中设置固定的行和列?

(there should be 9x9 positions, but as shown some of the lines are merged)

(应该有9x9个位置,但如图所示,某些线路合并)

1 个解决方案

#1


2  

If you need to "skip" some cells, just add a filler, for example empty new JLabel() where there will be "no button".

如果你需要“跳过”某些单元格,只需添加一个填充符,例如空的新JLabel(),其中将有“无按钮”。

#1


2  

If you need to "skip" some cells, just add a filler, for example empty new JLabel() where there will be "no button".

如果你需要“跳过”某些单元格,只需添加一个填充符,例如空的新JLabel(),其中将有“无按钮”。