Solved

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

Posted on 2008-10-04
3
1,659 Views
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().setPreferredSize(Toolkit.getDefaultToolkit().getScreenSize());
    getDemoPanel().setLocation(0, 0);
    frame.setDefaultCloseOperation(frame.DISPOSE_ON_CLOSE);
    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 + "?",
                                            ImageMap.GetText(63),
                                            msg.YES_NO_CANCEL_OPTION,
                                            msg.QUESTION_MESSAGE, msg.getIcon());
            if (odg == msg.YES_OPTION) {
              try {
                Drw_pro.con_ref.commit();
              }
              catch (Exception ex) {}
            }
            else if (odg == msg.CANCEL_OPTION) {
              //Drw_pro.spremenjeno = false;
              return;
            }
            else if (odg == msg.NO_OPTION) {
              try {
                Drw_pro.con_ref.rollback();
              }
  etc.............etc.............etc

Open in new window

0
Comment
Question by:spartanac86
3 Comments
 
LVL 17

Accepted Solution

by:
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:

http://java.sun.com/docs/books/tutorial/uiswing/events/componentlistener.html

And here is tutorial for the state listener:

https://www.cs.auckland.ac.nz/references/java/java1.5/tutorial/uiswing/events/windowlistener.html
0
 

Author Comment

by:spartanac86
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?
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

813 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now