How can I deactivate a JFrame
(up to while new frame is active) under a new frame just like JOptionPane.showMessageDialog(null,"Abc");
in Java
?
Asked
Active
Viewed 399 times
0

Andrew Thompson
- 168,117
- 40
- 217
- 433

razu
- 120
- 1
- 8
-
1Please clarify "deactivate". – martinez314 Jun 24 '14 at 19:50
-
This topic is covered here: [How to make a JFrame Modal in Swing java][1] [1]: http://stackoverflow.com/questions/1481405/how-to-make-a-jframe-modal-in-swing-java – Damian Polan Jun 24 '14 at 20:00
-
See [The Use of Multiple JFrames, Good/Bad Practice?](http://stackoverflow.com/a/9554657/418556) – Andrew Thompson Jun 25 '14 at 02:07
1 Answers
2
I assume you mean that you want to prevent access to the underlying JFrame
similar to how a JOptionPane
works. This functionality is possible by using a modal JDialog
window. Take a look at setModalityType
. More specifically, here is how you might create a modal JDialog
:
JFrame frame = new JFrame();
JDialog window = new JDialog(frame); // the frame is the parent
window.setModalityType(ModalityType.APPLICATION_MODAL);
window.setVisible(true); // must set modality first before making visible

David Yee
- 3,515
- 25
- 45