Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4530952

Double Mouse clicks needed to invoke Event using JDK1.3.1_01

    XMLWordPrintable

Details

    • hopper
    • generic, x86
    • generic, windows_nt
    • Verified

    Description


      I have a window with an editable combo box and a button. When user types text or selects an item in the combo box, the button will be enabled. When the user clicks on the button, the system will pop up a message box. However, it will take two clicks for the action to take place running with JDK1.3.1_01. It was working fine in JDK 1.2.2

      import javax.swing.*;
      import javax.swing.event.*;
      import java.awt.event.*;

      public class TestButtonAction extends JFrame implements ActionListener, DocumentListener {

          JButton btnAction = new JButton("Action");
          JComboBox cmbAction = new JComboBox();

          public TestButtonAction() {
              this.getContentPane().setLayout(null);
              this.setSize(200,100);

              // Add an editable combo box
              cmbAction.setEditable(true);
              cmbAction.setBounds(10,10,100,20);
              this.getContentPane().add(cmbAction);

              btnAction.setEnabled(false);
              btnAction.setBounds(120,10,70,20);
              this.getContentPane().add(btnAction);

              btnAction.addActionListener(this);
              cmbAction.addActionListener(this);
                    ((JTextField)cmbAction.getEditor().getEditorComponent()).getDocument().addDocumentListener(this);
          }

          public void actionPerformed(ActionEvent event) {
              Object source = event.getSource();

              System.out.println("In actionPerformed():" + source);

              if (event.getSource() == cmbAction) {
                  System.out.println("Action event for cmbAction");
              } else if (source == btnAction) {
                  System.out.println("Action event for btnAction");
                  JOptionPane.showMessageDialog(this, "Action Button clicked");
              }
          }

          public void changedUpdate(DocumentEvent evt) {
              System.out.println("Document: changedUpdate");
              resetButtons();
          }

          public void insertUpdate(DocumentEvent evt) {
              System.out.println("Document: insertUpdate");
              resetButtons();
          }

          public void removeUpdate(DocumentEvent evt) {
              System.out.println("Document: removeUpdate");
              resetButtons();
          }

          public void resetButtons() {
              int length = ((JTextField)cmbAction.getEditor().getEditorComponent()).getDocument().getLength();
              btnAction.setEnabled(length > 0);
              System.out.println("In resetButtons(): " + cmbAction.isEnabled());
          }

          public static void main(String[] args) {
              TestButtonAction tb = new TestButtonAction();
              tb.setVisible(true);
          }
      }


      Attachments

        Issue Links

          Activity

            People

              peterz Peter Zhelezniakov
              atongschsunw Albert Tong-schmidt (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: