JDialog in front of its parent JFrame

I want to create a Java Swing JDialog, which, when it opens, will not be able to access its parent window (the same as when opening the file explorer dialog box in Microsoft Word). Is there any method in the JDialog class that provides this behavior?

+3
source share
4 answers

use JDialog.setModal (true) before setting the dialog visible

JDialog yourdialog = ...

yourdialog.setModal(true);
...

yourdialog.setVisible(true);
+6
source

You have two options:

Use static methods in JOptionPane. They will create modal dialogs by default:

Window parentWindow = SwingUtilities.getWindowAncestor(parentPanel);
JOptionPane.showMessageDialog(parentWindow, "Hello, World); // Create modal dialog aligned with parent window.

Create JDialogexplicitly:

Window parentWindow = SwingUtilities.getWindowAncestor(parentPanel);
JDialog dlg = new JDialog(parentWindow, ModalityType.APPLICATION_MODAL);

, .

+3

, , .

, . ( ). Wikipedia :

, ,

, "" , ( - , ), "" "" , .

This is a concept that exists in the GUI infrastructure as a whole, and not just in the Swing framework. In any graphical environment that you use, you can find such functionality by looking for a property modal.

+1
source

how to lock jdialog inside its parent jframe? it is true that using JDialog.setModal you can make jdialog the same way as a dialog in another application. stopped all frames before jDialog closed

0
source

Source: https://habr.com/ru/post/1764711/


All Articles