在定位我的 JLabel 时,我发现了一个问题,直到现在我还无法解决。 JLabel 重叠。
这是关于网格布局的代码片段:
c = new GridBagConstraints();
c.gridx = 0;
c.gridy = 0;
c.gridwidth = 3;
c.fill = GridBagConstraints.HORIZONTAL;
c.ipady = 20;
c.weightx = 3;
c.weighty = 1;
c.insets = new Insets(0,5,5,5);
all.add(header, c);
c.gridx = 0;
c.gridy = 1;
c.weightx = 2;
c.weighty = 4;
c.insets = new Insets(5,5,5,5);
all.add(sts, c); //this label overlapped
c.gridx = 1;
c.gridy = 1;
c.weightx = 1;
c.weighty = 5;
c.insets = new Insets(5,5,5,5);
all.add(cl, c); //this label overlapped
提前致谢
最佳答案
gridwidth 为 3 意味着组件将在 x 网格中占据 3 个位置,请阅读 grid bag 布局教程 http://docs.oracle.com/javase/tutorial/uiswing/layout/gridbag.html
第一个组件位于 x0,这会将 3 列扩展到 x2,因此下一个可用网格位置是 x3
关于java - 使用 GridBagLayout 时组件重叠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15782148/