有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java MigLayout面板位于MigLayout面板内,将其与底部对齐

enter image description here

右边的面板上有所有的按钮,我想与底部对齐

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

我想我可以在所有按钮上方添加一个组件,并使其在y维度上增长以填充屏幕,但我不确定我会使用什么组件,我找不到任何设计用于实现这一点的组件


共 (1) 个答案

  1. # 1 楼答案

    我要做的是在“easternDock”面板中有另一个包含所有组件的面板,并让“easternDock”使用推列/行约束将另一个面板推到底部

    从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.

    以下是一个例子:

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