Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between a JFrame and a JDialog?

What is the difference between a JFrame and a JDialog?

Why can't we use setDefaultCloseOperation(JDialog.EXIT_ON_CLOSE); for a JDialog?

like image 258
Mahdi_Nine Avatar asked Apr 05 '11 13:04

Mahdi_Nine


People also ask

What is 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.

What is difference between JFrame and Swing?

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.

What is the difference between JFrame and JPanel?

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.

What is the main difference between dialog and frame?

Frame vs DialogFrame has maximize and minimize buttons but Dialog doesn't have.


2 Answers

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.

like image 100
fortran Avatar answered Sep 21 '22 15:09

fortran


Why we can't use setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE); for JDialog?

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.

like image 40
camickr Avatar answered Sep 23 '22 15:09

camickr