我应该使用JFrame还是JDialog? [英] Should I use JFrame or JDialog?
问题描述
在我的GUI中,通过单击帮助"按钮,我想在其中打开一个新窗口,其中包含通过JEditorPane
存储在HTML中的som文本信息.我的问题是:
In my GUI, by clicking on the button "Help", I want to open a new window within it containing som text information stored in HTML via JEditorPane
. My question is:
- 是否应该在JDialog或JFrame中存储JEditorPane对象的实例?
- 两个组件都可以提供哪些优点/缺点?
我不想在此窗口中进行任何操作,它仅用于显示文本信息.
I do not want to make any operations within this window, it will just serve to show the text information.
推荐答案
JDialog
和JFrame
之间的区别在于,JDialog
没有最大化/最小化按钮,并且您不能在其上设置DefaultCloseOperation.
The differences between JDialog
and JFrame
are, that JDialog
has no maximize/minimize button, and you can not set a DefaultCloseOperation on it.
JDialog
还会阻塞其他组件,直到将其关闭(等待用户交互).因此,如果您将其用作帮助"窗口,则用户将无法使其在后台打开并继续使用您的应用程序.
Also a JDialog
blocks other components until it is closed (it waits for userinteraction). So if you use it as "Help" window, the user could not leave it open in background and continue working with your application.
如果用户只能阅读您的信息文本,而不能与您的帮助进行交互,则您应该使用 JFrame
.
If the user can only read your info text, and can not interact with your help, you should use a JFrame
.
如果用户可以选择JDialog
,则应使用JDialog
.按下Ok
或Cancel
键,他应该在选择某项之前不能执行任何操作.
A JDialog
should be used if the user has the choice e.g. of pressing Ok
or Cancel
, and he should not be able to do anything before he has choosen something.
这篇关于我应该使用JFrame还是JDialog?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!