What is the difference between a JFrame
and a JDialog
?
Why can't we use setDefaultCloseOperation(JDialog.EXIT_ON_CLOSE);
for a JDialog?
JDialog() : creates an empty dialog without any title or any specified owner. JDialog(Frame o) :creates an empty dialog with a specified frame as its owner. JDialog(Frame o, String s) : creates an empty dialog with a specified frame as its owner. and a specified title.
A JFrame is a Swing component which is the newer one, well today's java GUI development uses mostly Swing as an advantage you can have a lot of community support on it. as far as I know Swing has LookAndFeel Feature that you can configure to change the look of your GUI with just few line of codes.
Basically, a JFrame represents a framed window and a JPanel represents some area in which controls (e.g., buttons, checkboxes, and textfields) and visuals (e.g., figures, pictures, and even text) can appear.
Frame vs DialogFrame has maximize and minimize buttons but Dialog doesn't have.
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 with JOptionPane
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.
Why we can't use
setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE);
forJDialog
?
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 a JDialog
because that value is not supported which makes sense since a JDialog
is a "child" or "helper" window for your application which is represented by a JFrame
. Closing a dialog should not close the application.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With