在 Java 中设置对话框 window 大小的推荐方法是什么

What is the recommended way to set the size of a dialog window in Java

我有一个冗长的 Java class

public class EditDialog extends JPanel implements ActionListener, ... {
    private JButton editDialog;
    // lots of code

    public EditDialog (String setting){
        this.setting = setting;
        JPanel main = new JPanel();
        // lots of code
    }
}

此对话框可以调整大小,但默认尺寸太小。我想在保持缩放能力的同时默认设置更大的尺寸。我怎样才能做到这一点? getPreferredSizesetPreferredSize 似乎很有用,但我找不到如何使用这些函数的示例。

一般情况下,您会在顶层 frame/dialog 上调用 setSize(),然后再使其可见。

C.f。 Top Level Containers