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

[ComboBox] onAction is not fired when changing the value before showing the stage


    • Type: Bug
    • Status: Open
    • Priority: P4
    • Resolution: Unresolved
    • Affects Version/s: 8u40
    • Fix Version/s: tbd
    • Component/s: javafx
    • Labels:
    • Environment:

      Windows 8.1


      There seems to be an inconsistency in behavior of ComboBox, where the onAction event is not fired if we set the value of the combo box before showing the stage (first observed in 8u40 after the upgrade from 8u25). Is that expected, an implementation detail, or is it a possible bug introduced by a recent overhaul of the ComboBoxBase class? The JavaFX 8 API for ComboBoxBase for setOnAction specifies
      The ComboBox action, which is invoked _whenever the ComboBox value property is changed. This may be due to the value property being programmatically changed_, when the user selects an item in a popup list or dialog, or, in the case of editable ComboBoxes, it may be when the user provides their own input (be that via a TextField or some other input mechanism.
      however it doesn't tell if this behavior depends on whether the control's stage is shown or not.
      Could one please clarify?

      Steps to reproduce:
      1. Run Test.java (source below).
      2. comboTest is shown with the "First" choice, however System.out (fired from onAction) doesn't display that.
      3. Choose a different value ("Second"). System.out displays this value.
      4. Modify Test.java to set the same comboTest value _after_ stage.show() instead.
      5. The same "First" choice is displayed when the stage is shown, but this time it's also indicated in System.out.


      package test;

      import java.util.ArrayList;
      import java.util.List;

      import javafx.application.Application;
      import javafx.collections.FXCollections;
      import javafx.fxml.FXML;
      import javafx.scene.Scene;
      import javafx.scene.control.ComboBox;
      import javafx.stage.Stage;

      public class Test extends Application {
        @FXML private ComboBox<String> comboTest;

        public static void main(String []args) {

        public void start(Stage stage) throws Exception {
          comboTest = new ComboBox<>();
          Scene scene = new Scene(comboTest);
          List<String> options = new ArrayList<>();
          comboTest.setOnAction(event -> System.out.println(comboTest.getValue()));
          // comboTest.setValue(options.get(0));


          Issue Links



              • Assignee:
                duke J. Duke (Inactive)
              • Votes:
                0 Vote for this issue
                2 Start watching this issue


                • Created: