2015-02-11 66 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)); 
相關問題