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

JOptionPane PropertyChangeListener not called when same button is pressed twice

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 1.2.0
    • client-libs



      Name: skT88420 Date: 04/16/99


      In How to Make Dialogs in the Java Tutorial, counsel is given
      about using a PropertyChangeListener to intercept JOptionPane
      button presses. See page 7 of dialog.html. Sample source code
      appears in CustomDialog.java. However, an important fact is
      missing in the discussion. The example and source code show that
      the dialog is setVisible (false) when exiting. If one then
      reshows the same dialog instance with setVisible (true) and then
      presses the same button again, a firePropertyChangeEvent () is
      called just like before. But alas, the oldValue and newValue of
      the property being changed are the same (because the user pressed
      the *same* button), resulting in no property change event
      actually being fired! So the user experience is that pressing the
      OK button, for example, the first time works but does not work
      when pressing it again if the dialog is brought back a second
      time. Ouch!

      Alternatively, if one does some kind of range checking when the
      OK button is pressed, detects an error, puts up an error dialog,
      and then allows the user to correct the error, then the OK button
      no longer works. Ouch again!

      I interpret this deplorable situation as a bug in JOptionPane.
      Ideally, it *should* reset the property value to null somehow so
      that subsequent presses of the same button will work.

      You may see this as a programmer error. The simple workaround
      described below works, but at the least should have been
      documented in the Java Tutorial. I have sent a similar message
      to the Java Tutorial authors.

      Please note that because of the successful workaround provided,
      I've listed the Impact on User, below, as "No Impact." It's still
      a bug, at least in the Java Tutorial documentation if not in
      the JOptionPane source code.

      I've also listed the Symptoms as causing the program to hang
      because that's what the user sees -- a dialog such that pressing
      the Okay button doesn't go away and process anything.
      (Review ID: 54563)
      ======================================================================

            amfowler Anne Fowler (Inactive)
            skonchad Sandeep Konchady
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: