将 GridBagLayout 的最后一个元素固定到页面底部
Fix the last element of a GridBagLayout to the bottom of the page
我有一个 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));
无法在您的上下文中尝试此操作,但这应该会使其固定在底部:
contentPanel.add(startButton,
new GridBagConstraints(0, 1, 1, 1, 1, 1, GridBagConstraints.PAGE_END,
GridBagConstraints.CENTER, new Insets(180, 0, 0, 0), 0, 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));
我有一个 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));
无法在您的上下文中尝试此操作,但这应该会使其固定在底部:
contentPanel.add(startButton,
new GridBagConstraints(0, 1, 1, 1, 1, 1, GridBagConstraints.PAGE_END,
GridBagConstraints.CENTER, new Insets(180, 0, 0, 0), 0, 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));