How to make Modal JFrame

I'm creating a JFrame(parent) which in turn creates another JFrame(child). Until the child frame is active the parent frame should be disabled i.e it should be modal.
bhagwandAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

expertmbCommented:
hi,

  when u r calling the child frame in that method use


  parentFrame.disable();


 mb...
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
expertmbCommented:
hi,
  u can use
 
  parentFrame.setEnabled(false)
 
  while closing the childframe
 
   parentFrame.setEnabled(true)
 
 this will solve ur problem

 good luck
 
 mb...
0
expertmbCommented:
hi bhagwand,

will this help u

import javax.swing.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
import java.net.*;

public class frameTest extends JFrame{

      public frameTest(){
      super("Frame Test") ;

      Container container = this.getContentPane();
      

      JMenuBar menuBar = new JMenuBar();
      JMenu frame = new JMenu("Frame");
      JMenuItem Frame = new JMenuItem("Child Frame");
      
      frame.add(Frame);
      menuBar.add(frame);

      setJMenuBar(menuBar);

      Frame.addActionListener(new FrameListener());


      addWindowListener(new WindowEventHandler())      ;
      setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
      setSize(500,500);
      show();

      }

      class FrameListener implements ActionListener{
            public void actionPerformed(ActionEvent ae){
                  setEnabled(false);                  
                   final JFrame frame1 = new JFrame("Child Frame");
                  frame1.setSize(300,300);
                  frame1.setEnabled(true);
                  frame1.show();
                  
               frame1.addWindowListener(new WindowAdapter(){
                    public void windowClosing(WindowEvent evt){
                    frame1.dispose();
                    setEnabled(true);
                    toFront();
                         }
                });
            }
      }
      

      public static void main(String [] args){
            new frameTest();
      }
      
      class WindowEventHandler extends WindowAdapter{
            public void windowClosing(WindowEvent evt){
                  System.exit(0);
       }
     }
}


good luck

mb...
 
0
heyhey_Commented:
>> parent frame should be disabled i.e it should be modal.


you can use MODAL JDialog, but not modal JFrame.
0
mbormannCommented:
Join the club yaar ,Merry christams man.
Click on my profile for answer.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.