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

ChoiceBox events ON_SHOWN, ON_SHOWING, ON_HIDDEN, ON_HIDING are not fired properly

XMLWordPrintable

    • x86_64
    • windows_7

      FULL PRODUCT VERSION :
      java version "1.8.0_121"
      Java(TM) SE Runtime Environment (build 1.8.0_121-b13)
      Java HotSpot(TM) 64-Bit Server VM (build 25.121-b13, mixed mode)


      ADDITIONAL OS VERSION INFORMATION :
      Microsoft Windows [Version 6.1.7601]

      A DESCRIPTION OF THE PROBLEM :
      When using setOnShown, setOnShowing, setOnHidden, setOnHiding methods of a ChoiceBox, the listeners are not executed.

      Possible reason is that the wrong event types are fired (snippet from the source):

      Event.fireEvent(this, value ? new Event(ComboBoxBase.ON_SHOWN) :
                  new Event(ComboBoxBase.ON_HIDDEN));

      Problem is described here: http://stackoverflow.com/questions/42641744/choicebox-onshown-onhidden-methods-dont-work-javafx/42642445#42642445



      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      final ComboBox<String> comboBox = new ComboBox<>();
           
         comboBox.getItems().addAll(
                      "jacob.smith@example.com",
                      "isabella.johnson@example.com"
              );

      choiceBox.setOnShown(event -> {
                  System.out.println("ChoiceBox onShown");
                  System.out.println(choiceBox.getSelectionModel().getSelectedIndex());
              });

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The messages are printed to the console.
      ACTUAL -
      The messages are not printed to the console.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      CUSTOMER SUBMITTED WORKAROUND :
              choiceBox.addEventFilter(ComboBoxBase.ON_SHOWN, e -> System.out.println("ComboBoxBase.ON_SHOWN was fired"));

              choiceBox.addEventFilter(ComboBoxBase.ON_HIDDEN, e -> System.out.println("ComboBoxBase.ON_HIDDEN was fired"));

              choiceBox.addEventFilter(ComboBoxBase.ON_HIDING, e -> System.out.println("ComboBoxBase.ON_HIDING was fired"));
              choiceBox.addEventFilter(ComboBoxBase.ON_SHOWING, e -> System.out.println("ComboBoxBase.ON_SHOWING was fired"));

            pmangal Priyanka Mangal (Inactive)
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: