JFrame 和 JDialog 有什么区别?
JFrame
和 JDialog
之间有什么区别?
为什么我们不能对 JDialog 使用 setDefaultCloseOperation(JDialog.EXIT_ON_CLOSE);
?
What is the difference between a JFrame
and a JDialog
?
Why can't we use setDefaultCloseOperation(JDialog.EXIT_ON_CLOSE);
for a JDialog?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
JFrame
是一个普通窗口,带有普通按钮(可选)和装饰。另一侧的JDialog
没有最大化和最小化按钮,通常使用JOptionPane
静态方法创建,并且更适合使它们成为模式(它们会阻止其他组件,直到他们已关闭)。但两者都继承自 Window,因此它们共享许多功能。
JFrame
is a normal window with its normal buttons (optionally) and decorations.JDialog
on the other side does not have a maximize and minimize buttons and usually are created withJOptionPane
static methods, and are better fit to make them modal (they block other components until they are closed).But both inherit from Window, so they share much functionality.
当然可以。
发布您的 SSCCE 来演示您在使用此值时遇到的问题。
但是,您不能将
EXIT_ON_CLOSE
用于JDialog
,因为不支持该值,这是有道理的,因为JDialog
是“子”或“应用程序的“helper”窗口,由JFrame
表示。关闭对话框不应关闭应用程序。Sure you can.
Post your SSCCE that demonstrates the problem you are having when using this value.
However you can't use
EXIT_ON_CLOSE
for aJDialog
because that value is not supported which makes sense since aJDialog
is a "child" or "helper" window for your application which is represented by aJFrame
. Closing a dialog should not close the application.有一些带有
owner
参数的JDialog
构造函数,该参数可以是Frame
、Dialog
或窗口
。非空值还使JDialog
保持在其所有者上方。这是对 Fortran 描述的模态行为的补充。There are some
JDialog
constructors with aowner
parameter which can be aFrame
, aDialog
or aWindow
. A non-null value also makes theJDialog
stay above his owner. This is complementary of the modal behavior described by Fortran.您还可以使用 setModal(boolean t);
这只适用于
JDialog
。用户必须在JDialog
上操作,而不是在其他窗口上操作。如果他们想要操作所有者窗口,则必须关闭此JDialog
。You can also use
setModal(boolean t);
This only works on
JDialog
. User must operate onJDialog
not other window. If they wanna operate owner windows, they must shut down thisJDialog
.