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