将GridBagLayout的最后一个元素固定到页面底部

时间:2015-02-11 15:57:47

标签: java swing gridbaglayout

我有一个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));

2 个答案:

答案 0 :(得分:0)

不能在你的上下文中尝试这个,但这应该让它坚持到底:

contentPanel.add(startButton,
   new GridBagConstraints(0, 1, 1, 1, 1, 1, GridBagConstraints.PAGE_END,
            GridBagConstraints.CENTER, new Insets(180, 0, 0, 0), 0, 0));

答案 1 :(得分:0)

我能够这样做:

contentPanel.add(startButton, new GridBagConstraints(0, 3, 1, 1, 1, 0, GridBagConstraints.PAGE_START,
                GridBagConstraints.CENTER, new Insets(-180, 0, 0, 0), 0, 0));