Override JFrame Minimization

I am doing a program with a registrar. The registrar has its own JFrame. I am trying to cancel the reaction by clicking on the button with a minimal click on this frame. I would like the frame to be either setVisible (false) or do defaultCloseOperation (since I set this to hide earlier).

How should I do it? thanks in advance

+3
source share
4 answers

Use JDialog instead of JFrame. There is no minimize button in JDialogs.

+8
source

You can add a WindowListener and add a meaningful handler that will respond when the window is minimized.

May be:

frame.addWindowListener(new WindowAdapter(){

      public void windowIconified(WindowEvent e){
            frame.setVisible(false);
      }
});
+2
source

WindowStateListener,

    f.addWindowStateListener(new WindowStateListener() {

        @Override
        public void windowStateChanged(WindowEvent arg0) {
            if (arg0.getNewState() == Frame.ICONIFIED) {
                // do stuff
            }

        }
    });
+1

:

frame.addWindowListener(new WindowAdapter() {
 @Override
         public void windowIconified(WindowEvent event) 
         {
            //do your stuff
         }
 });
0

All Articles