You really should try connecting JDialog to the parent dialog or frame, especially if you want it to be modal (by passing the parent window, the dialog will be attached to your window and casting the parent will result in the dialog of the child). Otherwise, the user interface can really go wrong: lost dialogs, blocking windows without viewing a modal dialog, etc.
JPanel, :
JPanel panel = new JPanel();
Window parentWindow = SwingUtilities.windowForComponent(panel);
Frame parentFrame = null;
if (parentWindow instanceof Frame) {
parentFrame = (Frame)parentWindow;
}
JDialog dialog = new JDialog(parentFrame);
...
, , "instanceof" .