src/macosx/classes/sun/lwawt/LWChoicePeer.java
Print this page
*** 1,7 ****
/*
! * Copyright (c) 2011, 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
--- 1,7 ----
/*
! * 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
*** 24,40 ****
*/
package sun.lwawt;
! import java.awt.Choice;
! import java.awt.Point;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.peer.ChoicePeer;
! import javax.swing.JComboBox;
final class LWChoicePeer extends LWComponentPeer<Choice, JComboBox<String>>
implements ChoicePeer, ItemListener {
/**
--- 24,40 ----
*/
package sun.lwawt;
! import java.awt.*;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.peer.ChoicePeer;
! import javax.accessibility.Accessible;
! import javax.swing.*;
final class LWChoicePeer extends LWComponentPeer<Choice, JComboBox<String>>
implements ChoicePeer, ItemListener {
/**
*** 157,163 ****
--- 157,190 ----
if (oldSelection != null && oldSelection.equals(anObject)) {
selectedItemChanged();
}
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;
+ }
}
}