【问题标题】:Components overlapping whilst using GridBagLayout使用 GridBagLayout 时组件重叠
【发布时间】:2013-04-03 08:16:36
【问题描述】:

在定位我的 JLabels 时,我发现了一个到目前为止我无法解决的问题。 JLabels 重叠。

这是关于 gridbaglayout 的代码中的一个 sn-p:

   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

提前致谢

【问题讨论】:

  • 再次寻求更好的帮助,尽快发布 SSCCE,可运行短,可编译,大约上午发行,

标签: java swing jlabel gridbaglayout


【解决方案1】:

gridwidth 为 3 表示组件将在 x 网格上占据 3 个位置,请阅读网格包布局教程 http://docs.oracle.com/javase/tutorial/uiswing/layout/gridbag.html

第一个组件位于 x0,这会将 3 列扩展到 x2,因此下一个可用网格位置是 x3

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-23
    • 2012-10-13
    • 1970-01-01
    • 1970-01-01
    • 2013-07-24
    • 1970-01-01
    相关资源
    最近更新 更多