【发布时间】:2023-03-30 18:50:01
【问题描述】:
我创建了一个 JDialog 以保持窗口模式,以阻止应用程序处理超过某个点。但是,当我使用这种方法时,会弹出框,但大小没有设置为 400,400,看起来好像没有大小。
public class test {
public static void main(String[] args) {
JFrame theDog = new JFrame();
JButton theButton = new JButton("hello");
//theDog.setSize(200, 200);
JDialog thadialog = new JDialog(theDog,"theTitle", Dialog.ModalityType.APPLICATION_MODAL);
thadialog.setVisible(true);
thadialog.setSize(400,400);
thadialog.pack();
System.out.println("hello");
}
}
如何让 JDialog 看起来有 400,400 的大小?
【问题讨论】:
-
把
setVisible放在pack()之后。试试dialog.setPreferredSize -
删除了这个包并添加了这个:thadialog.setPreferredSize(new Dimension(400,400)); ....还是什么都没有