I have created one GUI in which I have used a JFrame. How should I make it Modal?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Your best bet is to use a JDialog instead of a JFrame if you want to make the window modal. Check out details on the introduction of the Modality API in Java 6 for info. There is also a tutorial.
Here is some sample code which will display a
JPanel panelin aJDialogwhich is modal toFrame parentFrame. Except for the constructor, this follows the same pattern as opening aJFrame.Edit: updated Modality API link & added tutorial link (nod to @spork for the bump).