Uploaded image for project: 'Code Tools'
  1. Code Tools
  2. CODETOOLS-7902216

FrameOperator: waitState() is not waiting for actual state change

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Won't Fix
    • Icon: P3 P3
    • None
    • None
    • tools
    • generic
    • generic

      waitState() API is checking the state using getExtendedState(). Actually setExtendedState() will updated the 'state' variable first, then do the actual state change. So whenever it checks the state using getExtendedState() , the variable is changed but the actual state change will be ongoing/not completed.

      Code snippet from Frame.java:
      public void setExtendedState(int state) {
              if ( !isFrameStateSupported( state ) ) {
                  return;
              }
              synchronized (getObjectLock()) {
                  this.state = state;
              }
              // peer.setState must be called outside of object lock
              // synchronization block to avoid possible deadlock
              FramePeer peer = (FramePeer)this.peer;
              if (peer != null) {
                  peer.setState(state);
              }
          }

      public int getExtendedState() {
              synchronized (getObjectLock()) {
                  return state;
              }
          }

      Also some quote from javadoc of Frame.setExtendedState() " If the frame is currently visible on the screen (the isShowing method returns true), the developer should examine the return value of the java.awt.event.WindowEvent.getNewState method of the WindowEvent received through the java.awt.event.WindowStateListener to determine that the state has actually been changed.
      If the frame is not visible on the screen, the events may or may not be generated. In this case the developer may assume that the state changes immediately after this method returns. Later, when the setVisible(true) method is invoked, the frame will attempt to apply this state. Receiving any java.awt.event.WindowEvent.WINDOW_STATE_CHANGED events is not guaranteed in this case also."

      So we have to implement it using WindowStateListener

            akolarkunnu Abdul Kolarkunnu (Inactive)
            akolarkunnu Abdul Kolarkunnu (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: