简体   繁体   English

我应该使用JFrame还是JDialog?

[英]Should I use JFrame or JDialog?

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 . 在我的GUI中,通过单击“帮助”按钮,我想在其中打开一个新窗口,其中包含通过JEditorPane存储在HTML中的som文本信息。 My question is: 我的问题是:

  1. Should I store an instance of JEditorPane object within JDialog or JFrame? 我应该在JDialog或JFrame中存储JEditorPane对象的实例吗?
  2. What kind of pros/cons both components can offer? 两个组件可以提供什么样的优点/缺点?

I do not want to make any operations within this window, it will just serve to show the text information. 我不想在这个窗口中进行任何操作,它只是用来显示文本信息。

The differences between JDialog and JFrame are, that JDialog has no maximize/minimize button, and you can not set a DefaultCloseOperation on it. JDialogJFrame之间的区别在于, JDialog没有最大化/最小化按钮,您无法在其上设置DefaultCloseOperation。

Also a JDialog blocks other components until it is closed (it waits for userinteraction). JDialog也会阻止其他组件,直到它关闭(它等待用户交互)。 So if you use it as "Help" window, the user could not leave it open in background and continue working with your application. 因此,如果您将其用作“帮助”窗口,则用户无法在后台打开它并继续使用您的应用程序。

If the user can only read your info text, and can not interact with your help, you should use a JFrame . 如果用户只能阅读您的信息文本,并且无法与您的帮助进行互动, 则应使用 JFrame

A JDialog should be used if the user has the choice eg of pressing Ok or Cancel , and he should not be able to do anything before he has choosen something. 如果用户可以选择例如按OkCancel ,则应该使用JDialog ,并且在选择某些内容之前他不应该做任何事情。

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

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