-1

I'm trying to open a GUI and then wait until the JFrame is closed. I heard about JDialog but I don't know how to use it with my actual code:

GUI gui = new GUI();
gui.show(); // Creates some JButtons, JLabels, and show the JFrame.

Now I would like to wait until the JFrame is closed, but I don't know how to continue.

Can you help me please?

Slei
  • 15
  • 8
  • 2
    *"I heard about JDialog but I don't know how to use it with my actual code:"* Then [find out](https://docs.oracle.com/javase/tutorial/uiswing/components/dialog.html). That will be easier than making a frame behave in a modal manner. – Andrew Thompson Jul 08 '15 at 07:15
  • 1
    I'm voting to close this question as off-topic because it is about 'using a hammer to tighten a screw' (use a screw driver). – Andrew Thompson Jul 08 '15 at 07:16

1 Answers1

2

You can do it like this:

  • Inherit from JDialog instead of JFrame.
  • Call setModalityType(ModalityType.APPLICATION_MODAL) to make the dialog modal.
  • If you currently use the JFrame(LayoutManager) constructor, you have to call setLayout() to set the LayoutManager instead.
  • When you are done with your dialog, call setVisible(false) or dispose to continue with your program.

PS: Next time you should post working code that exposes your problem.

Axel
  • 13,939
  • 5
  • 50
  • 79