I need my JFrame
to freeze/ become inaccessible, similar to how it would with a model JDialog
or setEnabled(false)
.
In most cases I would use JDialog
but in this instance I am running a dialog through a C library.
Going down the setEnabled(false)
line also doesn't work because it, on setEnabled(true)
, will send the window to the back. And even using toFront()
will cause the window to go to the back for a split second then come to the front again.
Is there a better way to go about doing this, or an I stuck with the slight imperfection of the window flickering.
Also if you are familiar with the library I am using LWJGL's NativeFileDialog wrapper.
Asked
Active
Viewed 60 times
0

Jackson Brienen
- 61
- 9
-
1What about opening a JDialog, that just shows your app is waiting, then close the dialog when the LWJGL dialog is finished? – matt Jun 13 '22 at 11:00
-
1Oh, that's actually a concept that I hadn't thought of. I don't know if you are familiar but the OnlyOffice suite does that. Thank you for the idea! – Jackson Brienen Jun 13 '22 at 11:40
1 Answers
0
I have found a pretty good solution to this issue, originally answered as part of this post. It takes the idea of using a JDialog, but instead of displaying some message it is completely transparent, invisible to the user.
final JDialog modalBlocker = new JDialog();
modalBlocker.setModal(true);
modalBlocker.setUndecorated(true);
modalBlocker.setOpacity(0.0f);
modalBlocker.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
Then we can simply display our modal and show our file dialog
// Using invoke later we show our dialog after our frame has been blocked
// by setVisible(true)
SwingUtilities.invokeLater(()->{
// show dialog
});
modalBlocker.setVisible(true);
modalBlocker.dispose(); // immediately release resources
Then we can call modalBlocker.setVisible(false)
at any point to stop the modality effect on our frame.
Again this is the solution that worked for me, it is not mine. The code was written to integrate JavaFX with Swing by Sergei Tachenov, all credit goes to him!

Jackson Brienen
- 61
- 9