2016-01-20 67 views
0

enter image description here一個MigLayout面板內MigLayout面板 - 它對準底部

的面板與所有按鈕的權利,我想對齊的底部。

JPanel easternDock = new JPanel(new MigLayout("", "")); 
easternDock.add(button1, "wrap"); 
.... 
this.add(easternDock); 

我想我可以添加上述所有的按鈕組件,並使其在y維度擴展至整個屏幕,但我不知道我會用什麼成分爲可以和我找不到任何設計用於做這種事情的組件。

回答

3

我會這樣做的方法是在「easternDock」面板中包含所有組件,並使用「列」/「行」約束將「另一個面板」推到底部。

從米格金手指片:http://www.miglayout.com/cheatsheet.html

「:推」(或者,如果使用默認間隙大小用的「推」)可被加入到該間隙尺寸,以使該間隙貪婪並嘗試採取儘可能多的空間,而不會使佈局大於容器。

下面是一個例子:

public class AlignToBottom { 

public static void main(String[] args) { 
    JFrame frame = new JFrame(); 

    // Settings for the Frame 
    frame.setSize(400, 400); 
    frame.setLayout(new MigLayout("")); 
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 

    // Parent panel which contains the panel to be docked east 
    JPanel parentPanel = new JPanel(new MigLayout("", "[grow]", "[grow]")); 

    // This is the panel which is docked east, it contains the panel (bottomPanel) with all the components 
    // debug outlines the component (blue) , the cell (red) and the components within it (blue) 
    JPanel easternDock = new JPanel(new MigLayout("debug, insets 0", "", "push[]")); 

    // Panel that contains all the components 
    JPanel bottomPanel = new JPanel(new MigLayout()); 


    bottomPanel.add(new JButton("Button 1"), "wrap"); 
    bottomPanel.add(new JButton("Button 2"), "wrap"); 
    bottomPanel.add(new JButton("Button 3"), "wrap"); 

    easternDock.add(bottomPanel, ""); 

    parentPanel.add(easternDock, "east"); 

    frame.add(parentPanel, "push, grow"); 
    frame.setLocationRelativeTo(null); 
    frame.setVisible(true); 

} 

}