gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 21:52:46 27 4
gpt4 key购买 nike

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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com