我想知道如何使用swing。我想要对齐3个面板,这样面板1就在面板2的顶部,而面板2又在面板3的顶部。每个面板都有自己的标签/按钮。
然后,其中的每一个都需要在面板中包含自己的标签/按钮。

发布于 2018-09-08 13:19:12
使用GridBagLayout或GridLayout。首先来看一下Laying Out Components Within a Container
GridBagLayout

setLayout(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
gbc.weightx = 1;
gbc.fill = GridBagConstraints.HORIZONTAL;
gbc.gridwidth = GridBagConstraints.REMAINDER;
add(new ExamplePane(1), gbc);
add(new ExamplePane(2), gbc);
add(new ExamplePane(3), gbc);GridLayout

setLayout(new GridLayout(0, 1));
add(new ExamplePane(1));
add(new ExamplePane(2));
add(new ExamplePane(3));重要
这两种布局之间存在显著差异,您需要阅读这两种布局的链接教程和支持文档,以了解它们的工作原理以及哪种布局最适合您的即时需求
https://stackoverflow.com/questions/52232202
复制相似问题