Java GridBagConstraints 的问题
所以,我需要我的布局看起来像这样:
{|Name| |Info||Tag||Id|}
现在它看起来像这样:
{|Name| |Info| |Tag| |Id|}
或多或少。这是我的代码:
GridBagConstraints c;
c = new GridBagConstraints(0, 0, 5, 1, .5, .1, GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(0,0,0,0), 5, 5);
header.add(name, c);
c = new GridBagConstraints(10, 0, 1, 1, .5, .1, GridBagConstraints.EAST, GridBagConstraints.BOTH, new Insets(1,1,1,1), 5, 5);
header.add(id, c);
c = new GridBagConstraints(8, 0, 2, 1, .5, .1, GridBagConstraints.EAST, GridBagConstraints.BOTH, new Insets(1,1,1,1), 5, 5);
header.add(tag, c);
c = new GridBagConstraints(6, 0, 2, 1, .5, .1, GridBagConstraints.EAST, GridBagConstraints.BOTH, new Insets(1,1,1,1), 5, 5);
header.add(info, c);
我应该如何更改它以获得所需的结果?
So, I need my layout to look like this:
{|Name| |Info||Tag||Id|}
Right now it looks like this:
{|Name| |Info| |Tag| |Id|}
More or less. Here is my code:
GridBagConstraints c;
c = new GridBagConstraints(0, 0, 5, 1, .5, .1, GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(0,0,0,0), 5, 5);
header.add(name, c);
c = new GridBagConstraints(10, 0, 1, 1, .5, .1, GridBagConstraints.EAST, GridBagConstraints.BOTH, new Insets(1,1,1,1), 5, 5);
header.add(id, c);
c = new GridBagConstraints(8, 0, 2, 1, .5, .1, GridBagConstraints.EAST, GridBagConstraints.BOTH, new Insets(1,1,1,1), 5, 5);
header.add(tag, c);
c = new GridBagConstraints(6, 0, 2, 1, .5, .1, GridBagConstraints.EAST, GridBagConstraints.BOTH, new Insets(1,1,1,1), 5, 5);
header.add(info, c);
How should I change this to get the desired result?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
水平 BoxLayout 可能更容易。您的代码将类似于:
EXAMPLE
OUTPUT
A horizontal BoxLayout might be easier. Your code would be something like:
EXAMPLE
OUTPUT