JDialog 调整大小时不要剪切底部面板

Don't cut bottom panel when JDialog resizes

JDialog 调整到更小的尺寸时,它将从下到上剪切。 但是如何使底部成为 "higher priority" 并且 JDialog 将首先切割顶部并保留底部未切割。

调整大小前:

调整大小后(顶部面板正常,但底部面板被剪切):

在这种情况下,我希望顶部面板被切割,底部面板可以

来源:

import java.awt.BorderLayout;
import java.awt.FlowLayout;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JPanel;

@SuppressWarnings("serial")
public class DlgTest extends JDialog {
    /**
     * Launch the application.
     */
    public static void main(String[] args) {
        try {
            DlgTest dialog = new DlgTest();
            dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
            dialog.setVisible(true);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * Create the dialog.
     */
    public DlgTest() {
        setBounds(100, 100, 450, 300);
        JPanel mainPanel = new JPanel(new BorderLayout());
        JPanel top = new JPanel(new FlowLayout());
        top.add(new JButton("t1"));
        top.add(new JButton("t2"));

        JPanel bottom = new JPanel(new FlowLayout());
        bottom.add(new JButton("b1"));
        bottom.add(new JButton("b2"));
        mainPanel.add(top, BorderLayout.PAGE_START);
        mainPanel.add(bottom, BorderLayout.PAGE_END);
        add(mainPanel);
    }

}

您可以使用 CENTERSOUTH 约束 BorderLayout :

mainPanel.add(top, BorderLayout.CENTER);
mainPanel.add(bottom, BorderLayout.SOUTH);

南方不应该被砍掉。