Duplicate :
|
Name: jk109818 Date: 08/08/2003 FULL PRODUCT VERSION : java version "1.4.0_03" Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0_03-b04) Java HotSpot(TM) Client VM (build 1.4.0_03-b04, mixed mode) FULL OS VERSION : Windows 2000 Professional A DESCRIPTION OF THE PROBLEM : When I invoke a JPopupMenu in a frame and it gets visible, clicking on any button once does not invoke its attached 'actionPerformed(...)' method. However, clicking for the second time does it. This requirement stems from the fact that I need to develop a widget that mimmicks the addressbar of the 'Internet Explorer', u type in a few text and a popup opens that matches that text in its history. Its focus always remains in the address textfield, but if you click on any other button it works. STEPS TO FOLLOW TO REPRODUCE THE PROBLEM : Kindly conduct the two tests as given below by compiling and running the java source code hereby submitted. First Test : ============ The class shows an editable JComboBox and a JButton when visible. Now click the down-arrow button of the JComboBox and make the drop-down popup visible. Then click on the "OK" button while the popup is visible. The popup gets hidden and a dialog is displayed in one go as it should be. Second Test : ============= Run the appilcation again. This time type something in the editable textfield of the JComboBox. A custom JPopupMenu with the text "Hello World" would be visible. Then click on the "OK" button while the popup is visible. The expected dialog is not shown. The custom JPopupMenu gets hidden. Now click on "OK" button again. The dialog is visible now. EXPECTED VERSUS ACTUAL BEHAVIOR : EXPECTED - When I click on the "OK" button in the "Second Test" the JPopupMenu should get hidden and the dialog gets displayed (as it happens for the "First Test") in one click. ACTUAL - As given in the "Second Test" REPRODUCIBILITY : This bug can be reproduced always. ---------- BEGIN SOURCE ---------- import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.text.*; import javax.swing.event.*; import javax.swing.plaf.basic.*; import java.util.*; public class JPopupTest extends JPanel implements DocumentListener, ActionListener { JButton button; Vector vec; JComboBox jcombobox; JPopupMenu jpopupmenu; BasicComboBoxEditor _bcbe; JTextField jtextfield; public JPopupTest() { vec = new Vector(); vec.addElement("One"); vec.addElement("Two"); vec.addElement("Three"); vec.addElement("Four"); vec.addElement("Five"); vec.addElement("Six"); vec.addElement("Seven"); vec.addElement("Eight"); vec.addElement("Nine"); vec.addElement("Ten"); jcombobox = new JComboBox(vec); jcombobox.setEditable(true); _bcbe = ((BasicComboBoxEditor) jcombobox.getEditor()); jtextfield = ((JTextField) _bcbe.getEditorComponent()); jtextfield.getDocument().addDocumentListener(this); add(jcombobox); button = new JButton("OK"); button.addActionListener(this); add(button); jpopupmenu = new JPopupMenu(); jpopupmenu.add("Hello World"); } public void insertUpdate(DocumentEvent e) {changedUpdate(e);} public void removeUpdate(DocumentEvent e) {changedUpdate(e);} public void changedUpdate(DocumentEvent e) { if(!jpopupmenu.isVisible()) jpopupmenu.show(jcombobox, 0, jcombobox.getHeight()); jtextfield.requestFocus(); } public void actionPerformed(ActionEvent e) { JOptionPane.showMessageDialog(this, "OK button was pressed"); } public static void main(String[] args) { JPopupTest test = new JPopupTest(); JFrame jframe = new JFrame(); jframe.getContentPane().add(test); jframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); jframe.setSize(200,100); jframe.setVisible(true); } } ---------- END SOURCE ---------- CUSTOMER SUBMITTED WORKAROUND : I have searched the bug database and found that this has some similarity with Bug Id : 4694797. In that case the problem was a bit different as the workaround evolved upon the idea that JPopupMenu was hidden and then the button got activated. However, my problem is that the button should have the focus while the JPopupMenu is visible. Although adding a 'MouseListener' to the button solves the problem, yet its not a practical solution as my frame may consist of many such buttons & widgets and adding 'MouseListener' to each and every one of them isn't a good workaround. Release Regression From : 1.3.1 The above release value was the last known release where this bug was known to work. Since then there has been a regression. (Incident Review ID: 193240) ======================================================================