0

Possible Duplicate:
“Always on Top” Windows with Java

I am using JFrames

I have a window(ex-Accounts) which gets called from a button in MainMenu.

As long as Accounts is opened i want to forbid the user from accessing MainMenu(which should be visible) unless he closes the Accounts window.

Community
  • 1
  • 1

1 Answers1

1

This means that you need your window to be modal. JDialog can be modal, you can either mention this in the constructor like this:

new JDialog(parent, true);

or starting with Java 1.6, you can set the ModalityType:

new JDialog(parent, modalityType);
Dan D.
  • 32,246
  • 5
  • 63
  • 79
  • i want to add such a property to a JFrame that i created(say accounts) i am an immature i tried using setEnable(false) on the previous window(say mainMenu) and after returning back from the accounts i set the mainMenu enabled again bt it did'nt work out – Vikash Singh Sisodia Aug 18 '12 at 08:25
  • Note that JOptionPane is a Dialog, so if you want to copy the exact behavior, just use JDialog. – Dan D. Aug 18 '12 at 08:27
  • isn't there any other option that can be used in Jframe all i want is TO FORBID USER FROM SELECTING ANY OUTER WINDOW, not the exact behavior of JDaialog – Vikash Singh Sisodia Aug 18 '12 at 08:31
  • I don't know of any other being available there. – Dan D. Aug 18 '12 at 08:32
  • @VikashSinghSisodia if you're attempting to stop people from interacting with windows outside the context of your application, then don't, just don't. If your interested in just your application, then JDialog is you best option. Tale closer look @ Dialog.ModalityType http://docs.oracle.com/javase/7/docs/api/java/awt/Dialog.ModalityType.html – MadProgrammer Aug 18 '12 at 09:54