-
Enhancement
-
Resolution: Won't Fix
-
P3
-
None
-
None
-
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
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
- relates to
-
CODETOOLS-7902207 Implement single AWT listener mechanism in jemmy
-
- Resolved
-