javaswingeventsjframecomponentlistener

How do I listen for window size change event


Possible Duplicate:
Java AWT/Swing: Get notified on change of position/size of my window

Is there an event for JFrame size changing? I tried

addWindowStateListener(new java.awt.event.WindowStateListener() {
          public void windowStateChanged(WindowEvent e) {
              System.out.println("Size Changed");
     }
   });

But it works only with minimizing and maximizing. I want to trigger even a small window (JFrame) size change done by dragging the edges. Thank you.


Solution

  • You can use a ComponentListener:

    myJFrame.addComponentListener(new ComponentAdapter() {
                public void componentResized(ComponentEvent e) {
                    System.out.println("Size Changed");
                }
            });