Should I use JFrame or JDialog?

浪子不回头ぞ 提交于 2019-12-25 02:03:13

问题


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:

  1. Should I store an instance of JEditorPane object within JDialog or JFrame?
  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.


回答1:


The differences between JDialog and JFrame are, that JDialog has no maximize/minimize button, and you can not set a DefaultCloseOperation on it.

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.

If the user can only read your info text, and can not interact with your help, you should use a JFrame.

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.



来源:https://stackoverflow.com/questions/16749755/should-i-use-jframe-or-jdialog

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!