2015-02-11 45 views
0

我有一个GridBagLayout。最后一个元素(startButton)会根据上面文本框中的文本数量上下跳转。有什么方法可以解决它的问题吗?我尝试将PAGE_START更改为PAGE_END,但这没有做任何事情。修复GridBagLayout的最后一个元素到页面底部

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)); 
+0

我不在您发布的代码中看不到PAGE_END。您可以尝试使用BorderLayout创建一个JPanel,将内容面板放在中心位置,并将按钮面板放在南面。 – 2015-02-11 16:20:35

+0

它没有任何效果。我尝试这样:contentPanel.add(startButton,new GridBagConstraints(0,1,1,1,1,GridBagConstraints.PAGE_END, GridBagConstraints.CENTER,newInsets(180,0,0,0),0, 0)); – dorien 2015-02-11 16:35:04

回答

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)); 
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)); 
相关问题