File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes How Can I Make JFrame modal? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "How Can I Make JFrame modal?" Watch "How Can I Make JFrame modal?" New topic

How Can I Make JFrame modal?

Ramses Tutoli

Joined: Sep 05, 2003
Posts: 26
I want to pop up a screen when a user starts up the app but no file exists, or the file doesn't contain the necessary property. But to do this I need the pop up to be modal.
I know that JDialogs can be modal, but they aren't top-level containers (or are they?). Anyways, the constructors for JDialogs all seem to take a parent container as an input parameter, so I don't know if I can use it the way I want. I looked at JOptionPane, but I can't use that because it doesn't allow me to add components, and I want to add a JFileChooser to my pop up for choosing the database path.
Ken Krebs
Ranch Hand

Joined: Nov 27, 2002
Posts: 451
You can use the JDialog(Frame owner) with owner==null to popup your modal dialog (when all else fails, read the Javadoc). I use my own custom dialog for server and client modes and simply use a JFileChooser for standalone mode before the main window is ever displayed.
BTW, some bartender will probably warn you soon about the JavaRanch naming policy. Please comply.

kktec<br />SCJP, SCWCD, SCJD<br />"What we observe is not nature itself, but nature exposed to our method of questioning." - Werner Heisenberg
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11776

Hi Ramses,
Welcome to JavaRanch.
We don't have many rules here, but one we do have is our naming policy. We do require you to have both a first and last name in your displayed name, although you may use an initial for the first name if you really want to. You can change your displayed name here.

The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
I agree. Here's the link:
subject: How Can I Make JFrame modal?
jQuery in Action, 3rd edition