United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-7132809 [macosx] MAXIMIZED_BOTH set before setVisible(true) hides Frame
JDK-7132809 : [macosx] MAXIMIZED_BOTH set before setVisible(true) hides Frame

Details
Type:
Bug
Submit Date:
2012-01-24
Status:
Closed
Updated Date:
2012-03-23
Project Name:
JDK
Resolved Date:
2012-02-16
Component:
client-libs
OS:
os_x
Sub-Component:
java.awt
CPU:
x86
Priority:
P2
Resolution:
Fixed
Affected Versions:
7
Fixed Versions:
7u4 (b11)

Related Reports
Relates:
Relates:

Sub Tasks

Description
Mac OS X 10.7.2 macmini4,1
Run a manual regression test java/awt/Frame/InitialMaximizedTest/InitialMaximizedTest : a Frame which should be displayed maximized is not visible at all. Comment out  setExtendedState(Frame.MAXIMIZED_BOTH) or move it after setVisible(True), and everything will work as expected.

                                    

Comments
EVALUATION

Looks like we have to postpone the CPlatformWindow.setWindowState() operation until the window gets shown.
                                     
2012-01-26
SUGGESTED FIX

--- old/src/macosx/classes/sun/lwawt/macosx/CPlatformWindow.java	2012-01-26 19:35:07.000000000 +0400
+++ new/src/macosx/classes/sun/lwawt/macosx/CPlatformWindow.java	2012-01-26 19:35:07.000000000 +0400
@@ -473,29 +473,70 @@
 
     @Override // PlatformWindow
     public void setVisible(boolean visible) {
+        final long nsWindowPtr = getNSWindowPtr();
+
         if (owner != null) {
             if (!visible) {
-                CWrapper.NSWindow.removeChildWindow(owner.getNSWindowPtr(), getNSWindowPtr());
+                CWrapper.NSWindow.removeChildWindow(owner.getNSWindowPtr(), nsWindowPtr);
             }
         }
 
         updateIconImages();
         updateFocusabilityForAutoRequestFocus(false);
 
+        if (!visible) {
+            // Cancel out the extended state
+            if (target instanceof Frame) {
+                switch (((Frame)target).getExtendedState()) {
+                    case Frame.ICONIFIED:
+                        CWrapper.NSWindow.deminiaturize(nsWindowPtr);
+                        break;
+                    case Frame.MAXIMIZED_BOTH:
+                        CWrapper.NSWindow.zoom(nsWindowPtr);
+                        break;
+                }
+            }
+        }
+
         LWWindowPeer blocker = peer.getBlocker();
         if (blocker == null || !visible) {
             // If it ain't blocked, or is being hidden, go regular way
-            setVisibleHelper(visible);
+            if (visible) {
+                CWrapper.NSWindow.makeFirstResponder(nsWindowPtr, contentView.getAWTView());
+                boolean isKeyWindow = CWrapper.NSWindow.isKeyWindow(nsWindowPtr);
+                if (!isKeyWindow) {
+                    CWrapper.NSWindow.makeKeyAndOrderFront(nsWindowPtr);
+                } else {
+                    CWrapper.NSWindow.orderFront(nsWindowPtr);
+                }
+            } else {
+                CWrapper.NSWindow.orderOut(nsWindowPtr);
+            }
         } else {
             // otherwise, put it in a proper z-order
-            CWrapper.NSWindow.orderWindow(getNSWindowPtr(), CWrapper.NSWindow.NSWindowBelow,
+            CWrapper.NSWindow.orderWindow(nsWindowPtr, CWrapper.NSWindow.NSWindowBelow,
                     ((CPlatformWindow)blocker.getPlatformWindow()).getNSWindowPtr());
         }
+
+        if (visible) {
+            // Re-apply the extended state
+            if (target instanceof Frame) {
+                switch (((Frame)target).getExtendedState()) {
+                    case Frame.ICONIFIED:
+                        CWrapper.NSWindow.miniaturize(nsWindowPtr);
+                        break;
+                    case Frame.MAXIMIZED_BOTH:
+                        CWrapper.NSWindow.zoom(nsWindowPtr);
+                        break;
+                }
+            }
+        }
+
         updateFocusabilityForAutoRequestFocus(true);
 
         if (owner != null) {
             if (visible) {
-                CWrapper.NSWindow.addChildWindow(owner.getNSWindowPtr(), getNSWindowPtr(), CWrapper.NSWindow.NSWindowAbove);
+                CWrapper.NSWindow.addChildWindow(owner.getNSWindowPtr(), nsWindowPtr, CWrapper.NSWindow.NSWindowAbove);
             }
         }
 
@@ -620,17 +661,17 @@
 
     @Override
     public void setWindowState(int windowState) {
+        if (!peer.isVisible()) {
+            // setVisible() applies the state
+            return;
+        }
+
         int prevWindowState = peer.getState();
         if (prevWindowState == windowState) return;
 
         final long nsWindowPtr = getNSWindowPtr();
         switch (windowState) {
             case Frame.ICONIFIED:
-                if (!peer.isVisible()) {
-                    // later on the setVisible will minimize itself
-                    // otherwise, orderFront will deminiaturize window
-                   return;
-                }
                 if (prevWindowState == Frame.MAXIMIZED_BOTH) {
                     // let's return into the normal states first
                     // the zoom call toggles between the normal and the max states
@@ -665,33 +706,6 @@
     //                          UTILITY METHODS
     // ----------------------------------------------------------------------
 
-    private void setVisibleHelper(boolean visible) {
-        final long nsWindowPtr = getNSWindowPtr();
-        if (visible) {
-            CWrapper.NSWindow.makeFirstResponder(nsWindowPtr, contentView.getAWTView());
-            boolean isKeyWindow = CWrapper.NSWindow.isKeyWindow(nsWindowPtr);
-            if (!isKeyWindow) {
-                CWrapper.NSWindow.makeKeyAndOrderFront(nsWindowPtr);
-            } else {
-                CWrapper.NSWindow.orderFront(nsWindowPtr);
-            }
-            if (target instanceof Frame) {
-                if (((Frame)target).getExtendedState() == Frame.ICONIFIED) {
-                    CWrapper.NSWindow.miniaturize(nsWindowPtr);
-                }
-            }
-            return;
-        }
-
-        if (target instanceof Frame) {
-            if (((Frame)target).getExtendedState() == Frame.ICONIFIED) {
-                CWrapper.NSWindow.deminiaturize(nsWindowPtr);
-            }
-        }
-
-        CWrapper.NSWindow.orderOut(nsWindowPtr);
-    }
-
     /*
      * Find image to install into Title or into Application icon.
      * First try icons installed for toplevel. If there is no icon
                                     
2012-01-26
EVALUATION

8-na: the fix is integrated as a part of 7113349.
                                     
2012-03-23



Hardware and Software, Engineered to Work Together