7144065: [macosx] Orphaned Choice popup window
authorleonidr
Thu, 19 Sep 2013 22:33:21 +0400
changeset 20146 019d103c3e40
parent 20145 08266da0533a
child 20147 78e51d8fcb92
7144065: [macosx] Orphaned Choice popup window Reviewed-by: anthony, serb Contributed-by: alexander.potochkin@oracle.com
jdk/src/macosx/classes/sun/lwawt/LWChoicePeer.java
--- a/jdk/src/macosx/classes/sun/lwawt/LWChoicePeer.java	Wed Sep 18 16:01:37 2013 -0700
+++ b/jdk/src/macosx/classes/sun/lwawt/LWChoicePeer.java	Thu Sep 19 22:33:21 2013 +0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -26,13 +26,13 @@
 
 package sun.lwawt;
 
-import java.awt.Choice;
-import java.awt.Point;
+import java.awt.*;
 import java.awt.event.ItemEvent;
 import java.awt.event.ItemListener;
 import java.awt.peer.ChoicePeer;
 
-import javax.swing.JComboBox;
+import javax.accessibility.Accessible;
+import javax.swing.*;
 
 final class LWChoicePeer extends LWComponentPeer<Choice, JComboBox<String>>
         implements ChoicePeer, ItemListener {
@@ -159,5 +159,32 @@
             }
             super.setSelectedItem(anObject);
         }
+
+        @Override
+        public void firePopupMenuWillBecomeVisible() {
+            super.firePopupMenuWillBecomeVisible();
+            SwingUtilities.invokeLater(new Runnable() {
+                @Override
+                public void run() {
+                    JPopupMenu popupMenu = getPopupMenu();
+                    if (popupMenu != null) {
+                        if (popupMenu.getInvoker() != LWChoicePeer.this.getTarget()) {
+                            popupMenu.setVisible(false);
+                            popupMenu.show(LWChoicePeer.this.getTarget(), 0, 0);
+                        }
+                    }
+                }
+            });
+        }
+
+        private JPopupMenu getPopupMenu() {
+            for (int i = 0; i < getAccessibleContext().getAccessibleChildrenCount(); i++) {
+                Accessible child = getAccessibleContext().getAccessibleChild(i);
+                if (child instanceof JPopupMenu) {
+                    return  (JPopupMenu) child;
+                }
+            }
+            return null;
+        }
     }
 }