简体   繁体   English

JFrame和JDialog有什么区别?

[英]What is the difference between a JFrame and a JDialog?

What is the difference between a JFrame and a JDialog ? JFrameJDialog什么区别?

Why can't we use setDefaultCloseOperation(JDialog.EXIT_ON_CLOSE); 为什么我们不能使用setDefaultCloseOperation(JDialog.EXIT_ON_CLOSE); for a JDialog? 对于JDialog?

JFrame is a normal window with its normal buttons (optionally) and decorations. JFrame是一个普通的窗口,有正常的按钮(可选)和装饰。 JDialog on the other side does not have a maximize and minimize buttons and usually are created with JOptionPane static methods, and are better fit to make them modal (they block other components until they are closed). 另一方面, JDialog没有最大化和最小化按钮,并且通常使用JOptionPane静态方法创建,并且更适合使它们成为模态(它们会阻止其他组件,直到它们被关闭)。

But both inherit from Window, so they share much functionality. 但两者都继承自Window,因此它们共享很多功能。

Why we can't use setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE); 为什么我们不能使用setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE); for JDialog ? 对于JDialog

Sure you can. 你当然可以。

Post your SSCCE that demonstrates the problem you are having when using this value. 发布您的SSCCE ,演示您在使用此值时遇到的问题。

However you can't use EXIT_ON_CLOSE for a JDialog because that value is not supported which makes sense since a JDialog is a "child" or "helper" window for your application which is represented by a JFrame . 但是,您不能将EXIT_ON_CLOSE用于JDialog因为不支持该值,因为JDialog是您的应用程序的“子”或“助手”窗口,由JFrame表示。 Closing a dialog should not close the application. 关闭对话框不应关闭应用程序。

There are some JDialog constructors with a owner parameter which can be a Frame , a Dialog or a Window . 有一些带有owner参数的JDialog构造函数可以是FrameDialogWindow A non-null value also makes the JDialog stay above his owner. 非null值也使JDialog保持在其所有者之上。 This is complementary of the modal behavior described by Fortran. 这是Fortran描述的模态行为的补充。

You can also use setModal(boolean t); 你也可以使用setModal(boolean t); This only works on JDialog . 这仅适用于JDialog User must operate on JDialog not other window. 用户必须在JDialog操作而不是其他窗口。 If they wanna operate owner windows, they must shut down this JDialog . 如果他们想操作所有者窗口,他们必须关闭这个JDialog

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM