3

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

mKorbel
  • 109,525
  • 20
  • 134
  • 319
Drareeg
  • 99
  • 2
  • 10
  • 3
    @user545236, Applications should only have a single JFrame. Other helper windows should be dialogs. The accepted answer may work, but it is not the proper usage of a JFrame, that is why JDialogs exist. – camickr May 04 '11 at 03:33

4 Answers4

8

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

camickr
  • 321,443
  • 19
  • 166
  • 288
2

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);
      }
});
nhahtdh
  • 55,989
  • 15
  • 126
  • 162
Vincent Ramdhanie
  • 102,349
  • 23
  • 137
  • 192
1

You can use the WindowStateListener like this

    f.addWindowStateListener(new WindowStateListener() {

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

        }
    });
Bala R
  • 107,317
  • 23
  • 199
  • 210
0

Try this:

frame.addWindowListener(new WindowAdapter() {
 @Override
         public void windowIconified(WindowEvent event) 
         {
            //do your stuff
         }
 });
  • 2
    Your answer repeat existing answer http://stackoverflow.com/a/5877604/1400768 with even less information or explanation. – nhahtdh Sep 21 '15 at 07:36