【问题标题】:MigLayout Panel inside a MigLayout panel - aligning it to the bottomMigLayout 面板内的 MigLayout 面板 - 将其与底部对齐
【发布时间】:2016-04-26 21:37:42
【问题描述】:

所有按钮都在右侧的面板,我想与底部对齐。

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

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

【问题讨论】:

    标签: java swing user-interface miglayout


    【解决方案1】:

    我这样做的方法是在“easternDock”面板中设置另一个面板,该面板包含所有组件,并让“easternDock”使用推送列/行约束将此另一个面板推到底部。

    来自 MiG 备忘单:http://www.miglayout.com/cheatsheet.html

    ":push"(如果与默认间隙大小一起使用,则为"push")可以添加到间隙大小以使该间隙贪婪并尝试占用尽可能多的空间而不使布局大于容器。

    这是一个例子:

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

    【讨论】:

      猜你喜欢
      • 2013-01-13
      • 2013-12-26
      • 2019-01-22
      • 2012-11-20
      • 1970-01-01
      • 2019-07-26
      • 2018-06-09
      • 2012-02-14
      • 2016-10-07
      相关资源
      最近更新 更多