FULL PRODUCT VERSION : JDK 7u9 ADDITIONAL OS VERSION INFORMATION : Apple Mac OS X 10.7 (Intel) (64-bit) A DESCRIPTION OF THE PROBLEM : An immediate call to JComboBox.showPopup() after JComboBox.hidePopup() does not lead to showing of a popup menu in JDK 7 on OS X, instead of this the popup menu just flashes. However the popup menu is always shown in JDK 6. STEPS TO FOLLOW TO REPRODUCE THE PROBLEM : 1. Compile and run the attached source code. 2. Click into any place of a displayed frame. REPRODUCIBILITY : The bug is reproduced always. ---------- BEGIN SOURCE ---------- import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; public class TestWTDComboBox { static JComboBox kb = null; static boolean dataPopulated = false; static AWTEvent event = null; static JFrame frame; public static void main(String[] args) { frame = new JFrame("Creating a JComboBox Component"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(400, 400); JPanel panel = new JPanel(); String anArray[] = {"BCA", "MCA", "PPC", "CIC"}; kb = new JComboBox(anArray) { @Override public void showPopup() { if (!dataPopulated) { frame.dispatchEvent(event); } super.showPopup(); } }; kb.addPopupMenuListener(new PopupMenuListener() { @Override public void popupMenuWillBecomeVisible(PopupMenuEvent e) { System.out.println("hello"); } @Override public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { kb.setPopupVisible(false); } @Override public void popupMenuCanceled(PopupMenuEvent e) {} }); panel.add(kb); frame.add(panel); frame.addMouseListener(new MouseListener() { @Override public void mouseClicked(MouseEvent e) { System.out.println("hello111"); event = e; test(); } @Override public void mousePressed(MouseEvent e) { System.out.println("hello111"); event = e; test(); } @Override public void mouseReleased(MouseEvent e) { System.out.println("hello111"); } @Override public void mouseEntered(MouseEvent e) { System.out.println("hello111"); } @Override public void mouseExited(MouseEvent e) { System.out.println("hello111"); } }); SwingUtilities.invokeLater(new Runnable() { public void run() { frame.setVisible(true); } }); } public static void test() { Object prevSel = kb.getSelectedItem(); boolean isDropDown = kb.isPopupVisible(); kb.hidePopup(); kb.removeAllItems(); kb.addItem("none"); kb.addItem("none1"); kb.addItem("none2"); kb.addItem("none3"); dataPopulated = true; kb.setSelectedItem(prevSel); kb.showPopup(); dataPopulated = false; } } ---------- END SOURCE ----------
|