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

标签 java swing user-interface miglayout

enter image description here

右侧面板包含所有按钮,我想与底部对齐。

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

我想我可以在所有按钮之上添加一个组件,并使其在 y 维度上增长以填充屏幕,但我不确定我会使用什么组件,而且我找不到任何组件设计用于执行此类操作的组件。

最佳答案

我的方法是在“easternDock”面板中创建另一个面板,其中包含所有组件,并让“easternDock”使用推送列/行约束将另一个面板推到底部。

来自米格备忘单: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.

这是一个例子:

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

}

}       

关于java - MigLayout 面板内的 MigLayout 面板 - 将其与底部对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34910246/

相关文章:

java - 将时区转换回本地时区

java - 为什么Java中Swing GUI关闭后新线程也会退出

java - 尝试将 JTextField 转换为 int 时出现 NumberFormatException

java - 压入并评估堆栈 <double>

java - 为什么不能将 double 值转换为 Byte 对象?

java - 尝试运行两个双 for 循环

java - 我的 Swing 应用程序是否分配了冗余对象?

C++/Tk如何执行一般的tcl代码?

java - 当我更改 SWT 中按钮的文本时,整个按钮的大小会发生变化。我怎样才能禁用这个功能?

Java GUI 按钮无法按下