【发布时间】:2015-02-11 15:57:46
【问题描述】:
我有一个 GridBagLayout。最后一个元素(startButton)根据上面文本框中的文本数量上下跳跃。有没有办法固定它的位置?我尝试将 PAGE_START 更改为 PAGE_END,但没有任何效果。
contentPanel.add(titleText, new GridBagConstraints(0, 0, 1, 1, 1, 0, GridBagConstraints.PAGE_START,
GridBagConstraints.HORIZONTAL, new Insets(50, 100, 0, 100), 0, 0));
contentPanel.add(expText, new GridBagConstraints(0, 0, 1, 1, 1, 0, GridBagConstraints.PAGE_START,
GridBagConstraints.CENTER, new Insets(120, 100, 00, 100), 0, 0));
contentPanel.add(buttonsPanel, new GridBagConstraints(0, 1, 1, 1, 1, 0, GridBagConstraints.PAGE_START,
GridBagConstraints.HORIZONTAL, new Insets(120, 100, 0, 100), 0, 0));
contentPanel.add(userText, new GridBagConstraints(0, 1, 1, 1, 1, 0, GridBagConstraints.PAGE_START,
GridBagConstraints.CENTER, new Insets(120, 0, 0, 0), 0, 0));
contentPanel.add(startButton, new GridBagConstraints(0, 1, 1, 1, 1, 0, GridBagConstraints.PAGE_START,
GridBagConstraints.CENTER, new Insets(180, 0, 0, 0), 0, 0));
contentPanel.add(Box.createVerticalGlue(), new GridBagConstraints(0, 1, 2, 2, 1, 1,
GridBagConstraints.PAGE_START, GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
【问题讨论】:
-
我在您发布的代码中没有看到 PAGE_END。您可以尝试创建一个带有 BorderLayout 的 JPanel,将内容面板放在中间,将按钮面板放在南方。
-
嗯,它没有;没有任何效果。我这样尝试: contentPanel.add(startButton, new GridBagConstraints(0, 1, 1, 1, 1, 0, GridBagConstraints.PAGE_END, GridBagConstraints.CENTER, new Insets(180, 0, 0, 0), 0, 0 ));
标签: java swing gridbaglayout