2016-01-20 66 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); 

} 

}