Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
有一个扩展 JDialog 的类。它完全在 EDT 上初始化(以防万一)。现在,
public PropsDialog (JFrame parentFrame) { super(parentFrame); // boring pack(); setLocationRelativeTo(getParent()); setVisible(true); }
导致对话框出现在最左角,然后跳转到它的预期位置。我做错了吗?
您能否提供一个工作示例和更多信息?例如,您在什么操作系统上进行测试?Swing 之间有一些差异,例如没有父级的 JDialogs 在 gnome 面板中获得条目,但在 Windows 任务栏中没有条目等。
其次,我猜想,在您调用 setLocationRelativeTo 之前,您的 JDialog 是可见的,可能在您评论为“无聊”的部分中有所体现。建议你快点打
System.out.println(isVisible());
进入你的代码,就在setLocationRelativeTo之前,以防万一......