1

I'm new to Java.

Yet, I've project to do with ;

1. a Main JFrame1 &
2. In JFrame1 I've got a Button1 for JFrame2.setVisible(true); &
3. another JFrame2.

What I need to know is: When User Clicks JFrame1->Button1

  1. How to make JFrame1 Completely inactive so that users can't either click a button on JFrame1 or focus JFrame1 while JFrame2 is active.

  2. I need to set, when JFrame2 is closed all of above like clicking/ Focusing are possible.

Thank You !

Hovercraft Full Of Eels
  • 283,665
  • 25
  • 256
  • 373
Harindra Singh
  • 371
  • 2
  • 6
  • 17
  • possible duplicate of [How to wait for a JFrame to close before continuing?](http://stackoverflow.com/questions/12335733/how-to-wait-for-a-jframe-to-close-before-continuing) – Hovercraft Full Of Eels Mar 30 '13 at 02:19
  • 2
    See [The Use of Multiple JFrames, Good/Bad Practice?](http://stackoverflow.com/a/9554657/418556) – Andrew Thompson Mar 30 '13 at 02:23
  • possible duplicate of [How to disable main JFrame when open new JFrame](http://stackoverflow.com/questions/3029079/how-to-disable-main-jframe-when-open-new-jframe) – fglez Apr 03 '13 at 11:03

1 Answers1

5

Have a look at using a modal dialog. It will prevent focus being switched to its parent window.

Reimeus
  • 158,255
  • 15
  • 216
  • 276
  • 2
    Yep, 1+ this same question gets asked over and over again and the answer is always the same -- use a modal JDialog or JOptionPane. Else you're stuck with using a WindowListener, but that's a more kludgy solution. – Hovercraft Full Of Eels Mar 30 '13 at 02:17