windowStateChanged(WindowEvent e) function doesn't work!!

Posted on 2008-10-04
Last Modified: 2013-11-23
i have a problem, windowStateChanged(WindowEvent e) simply doesn't get invoked when i resize my window or click on maximize button!!
all the other functions work fine, like windowOnClose, windowIconified...etc. i can't understand what's wrong so it won't invoke.

public void mainImpl() {
    frame = new JFrame(ImageMap.Promoto_Ver);
    frame.getContentPane().setLayout(new BorderLayout());
    frame.getContentPane().add(getDemoPanel(), BorderLayout.CENTER);
    getDemoPanel().setLocation(0, 0);
    frame.addWindowListener(new java.awt.event.WindowAdapter() {
      public void windowStateChanged(WindowEvent e) {
        msg.showMessageDialog(new Frame(), e.getComponent().getClass().getName() + " --- Resized ");    //this never gets invoked no matter what i do with my window!!!! why?        
      public void windowClosing(WindowEvent e) {
        if (Drw_pro.prozessID != 0) {
          if (Drw_pro.spremenjeno) {
            int odg = msg.showConfirmDialog(new Frame(),
                                            ImageMap.GetText(132) + " " +
                                            Drw_pro.pro_name + "?",
                                            msg.QUESTION_MESSAGE, msg.getIcon());
            if (odg == msg.YES_OPTION) {
              try {
              catch (Exception ex) {}
            else if (odg == msg.CANCEL_OPTION) {
              //Drw_pro.spremenjeno = false;
            else if (odg == msg.NO_OPTION) {
              try {

Open in new window

Question by:spartanac86
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 17

Accepted Solution

Dejan Pažin earned 250 total points
ID: 22643665

windowStateChanged does not listen for resize changes. You need ComponentListener for that, here is a tutorial:

And here is tutorial for the state listener:

Author Comment

ID: 22645450
i should have only changed ...frame.addWindowListener... to ...frame.addWindowStateListener...
and it would have worked fine for minimizing/maximizing, but for resizing i think i'll need to use component listener.
Class Window inherits Component, right?

Featured Post

The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn different types of Android Layout and some basics of an Android App.
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.
Simple Linear Regression

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question