开发者

Override minimize of JFrame

开发者 https://www.devze.com 2023-03-02 20:45 出处:网络
I\'m making a program with a logger. Th开发者_开发百科e logger has its own JFrame. I\'m trying to override the reaction from clicking on the minimize-button of that frame.

I'm making a program with a logger. Th开发者_开发百科e 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
         }
 });
0

精彩评论

暂无评论...
验证码 换一张
取 消