简体   繁体   English

MigLayout面板内部的MigLayout面板-将其与底部对齐

[英]MigLayout Panel inside a MigLayout panel - aligning it to the bottom

在此处输入图片说明

The panel to the right with all the buttons, I would like to align to the bottom. 右侧面板上有所有按钮,我想与底部对齐。

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

I'm thinking I could add a component above all the buttons and make it grow in the y dimension to fill the screen, but I'm not sure what component I'd use for that and I can't find any components designed to do such a thing. 我在想可以在所有按钮上方添加一个组件,并使其在y维度上增长以填充屏幕,但是我不确定该使用哪个组件,而且找不到任何旨在做这样的事情。

The way I would do it is to have another panel within the "easternDock" panel which contains all the components and have "easternDock" push this other panel to the bottom using the push Column/Row constraint. 我要做的方法是在“ easternDock”面板中包含另一个面板,其中包含所有组件,并让“ easternDock”使用“推入列/行”约束将另一个面板推向底部。

From the MiG Cheat sheet : http://www.miglayout.com/cheatsheet.html 在MiG备忘单中: http : //www.miglayout.com/cheatsheet.html

":push" (or "push" if used with the default gap size) can be added to the gap size to make that gap greedy and try to take as much space as possible without making the layout bigger than the container. 可以将“:push”(或“ push”,如果与默认间隙大小一起使用)添加到间隙大小中,以使该间隙变得贪婪,并尝试在不使布局大于容器的情况下占用尽可能多的空间。

Here is an example: 这是一个例子:

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

}

}       

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM