0

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?

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
razu
  • 120
  • 1
  • 8

1 Answers1

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