1

I have a main JFrame which link to another JFrame in purpose, lets assume main frame is M and child frame is C, when i click on M a JFrame C opens successfully and here i have added setAlwaysOnTop(true) method to C JFrame. Good every thing is working fine.

But when my C JFrame is on top i don't want my M JFrame actions work unless C JFrame is closed.

This seem to be little awkward and silly question. but please do answer

Intact Abode
  • 382
  • 5
  • 20
  • 1
    1) See [The Use of Multiple JFrames, Good/Bad Practice?](http://stackoverflow.com/q/9554636/418556). It's likely one of the frames should be `JDialog`, with the remaining frame as owner. 2) Don't randomly start words with capital (upper case) letters. Please use an upper case letter at the start of sentences, for the word I, and proper names like `ArrayList` or Oracle only. – Andrew Thompson May 04 '17 at 12:08
  • ya sorry for (upper case), but i only have 2 JFrame, using 2 frames is also not good practice? – Intact Abode May 04 '17 at 12:13
  • When you are opening frame **C** on button click then, do `M.setEnabled(false)` and when you are closing **C** do the reverse `M.setEnabled(true)` – Nishesh Pratap Singh May 04 '17 at 12:18
  • *"but i only have 2 JFrame, using 2 frames is also not good practice?"* Multiple means "**two** or more".. – Andrew Thompson May 04 '17 at 12:23
  • You are Just saying multiple frames is bad, bad but why don't you give me some alternate solution then. @David Tanzer helped me. i got the solution – Intact Abode May 04 '17 at 12:33

1 Answers1

2

From your description, it looks to me like you want a modal dialog.

Your C would basically be a JDialog, and you would set it to Dialog.ModalityType.APPLICATION_MODAL:

JFrame m = new JFrame(...);
JDialog c = new JDialog(m, "", Dialog.ModalityType.APPLICATION_MODAL );

Read more about modal dialogs here:

Community
  • 1
  • 1
David Tanzer
  • 2,732
  • 18
  • 30