# HG changeset patch # User leonidr # Date 1379615601 -14400 # Node ID 019d103c3e40ad1d3f19566b9d9892626397fa64 # Parent 08266da0533a198714c1854d4b9bc2c6a865e154 7144065: [macosx] Orphaned Choice popup window Reviewed-by: anthony, serb Contributed-by: alexander.potochkin@oracle.com diff -r 08266da0533a -r 019d103c3e40 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> 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; + } } }