简体   繁体   中英

Override minimize of JFrame

I'm making a program with a logger. The logger has its own JFrame. I'm trying to override the reaction from clicking on the minimize-button of that frame. I would like the frame to either setVisible(false) or do the defaultCloseOperation (as i set that to hide earlier).

How should I do this? Thanks in advance

Use a JDialog instead of a JFrame. JDialogs don't have a minimize button.

You can add a WindowListener and add a iconified handler that will react when the window is minimized.

Maybe:

frame.addWindowListener(new WindowAdapter(){

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

You can use the WindowStateListener like this

    f.addWindowStateListener(new WindowStateListener() {

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

        }
    });

Try this:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM