Java GridBagConstraints gridx and gridy not working?(Java GridBagConstraints gridx 和 gridy 不起作用?)
问题描述
我正在尝试使用 gridx
和 gridy
约束来定位我的按钮.但他们不工作!如果我更改 gridx
和 gridy
变量,什么也不会发生.如果我将 GridBagConstraints
的填充更改为 NONE
,它仍然不起作用.
I am trying to use the gridx
and gridy
constraints to position my button. But they do not work! If I change the gridx
and gridy
variables, nothing happens. If I change the fill to GridBagConstraints
to NONE
, it still does not work.
我错过了什么吗?
如果这很难阅读,问题就出在这里:
If that is hard to read, here is where the problem lies:
推荐答案
好久没做swing layout了,难道gridX和gridY不是只有在你的JPanel中有多个JComponent的时候才有效果吗?看来你只有一个 JButton,所以 GridBagLayout 没有任何布局可做.
It's been a while since I've done swing layouts, but don't gridX and gridY only have effects if you have more than one JComponent in your JPanel? It seems you only have a JButton, so the GridBagLayout doesn't have any layout to do.
这篇关于Java GridBagConstraints gridx 和 gridy 不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!