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

ChoiceBox using events from ComboBox

XMLWordPrintable

    • generic
    • generic

      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 :
      10.0.14393

      A DESCRIPTION OF THE PROBLEM :
      ChoiceBox events are not emited when ChoiceBox is interacted with.
      Instead ComboBox events is emited.
      This is either implementation bug or documentation mismatch.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Create simple application:

      public class StrangeBox extends Application {

          @Override
          public void start(Stage primaryStage) throws Exception {
              Pane pane = new Pane();
              ChoiceBox box = new ChoiceBox();
              box.getItems().addAll("Walk", "Run");

              pane.getChildren().addAll(box);

              Stream.of(ChoiceBox.ON_HIDDEN, ChoiceBox.ON_HIDING, ChoiceBox.ON_SHOWING, ChoiceBox.ON_SHOWN,
                      ComboBox.ON_HIDDEN, ComboBox.ON_HIDING, ComboBox.ON_SHOWING, ComboBox.ON_SHOWN)
                      .forEach(type -> box.addEventFilter(type, event -> System.out.println(type)));

              Scene scene = new Scene(pane);
              primaryStage.setScene(scene);
              primaryStage.setTitle("Choice box?");
              primaryStage.show();
          }
      }

      Run app fiddle with menu

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Any string in console starting with:
      CHOICE_BOX_ON_
      ACTUAL -
      Only string starting with:
      COMBO_BOX_BASE_ON_

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      package ru.latuhin.choice;

      import javafx.application.Application;
      import javafx.scene.Scene;
      import javafx.scene.control.ChoiceBox;
      import javafx.scene.control.ComboBox;
      import javafx.scene.layout.Pane;
      import javafx.stage.Stage;

      import java.util.stream.Stream;

      public class StrangeBox extends Application {

          @Override
          public void start(Stage primaryStage) throws Exception {
              Pane pane = new Pane();
              ChoiceBox box = new ChoiceBox();
              box.getItems().addAll("Walk", "Run");

              pane.getChildren().addAll(box);

              Stream.of(ChoiceBox.ON_HIDDEN, ChoiceBox.ON_HIDING, ChoiceBox.ON_SHOWING, ChoiceBox.ON_SHOWN,
                      ComboBox.ON_HIDDEN, ComboBox.ON_HIDING, ComboBox.ON_SHOWING, ComboBox.ON_SHOWN)
                      .forEach(type -> box.addEventFilter(type, event -> System.out.println(type)));

              Scene scene = new Scene(pane);
              primaryStage.setScene(scene);
              primaryStage.setTitle("Choice box?");
              primaryStage.show();
          }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Use ComboBox instead of ChoiceBox, or reregister existing ChoiceBox events to the ComboBoxBase events.

      SUPPORT :
      YES

            arapte Ambarish Rapte
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: