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

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

    Details

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

      Windows 8.1

      Description

      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
      {quote}
      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.
      {quote}
      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.

      Test.java:

      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) {
          launch(args);
        }

        @Override
        public void start(Stage stage) throws Exception {
        
          comboTest = new ComboBox<>();
          Scene scene = new Scene(comboTest);
          stage.setScene(scene);
          
          List<String> options = new ArrayList<>();
          options.add("First");
          options.add("Second");
          
          comboTest.setItems(FXCollections.observableList(options));
          comboTest.setOnAction(event -> System.out.println(comboTest.getValue()));
          
          comboTest.setValue(options.get(0));
          stage.show();
          // comboTest.setValue(options.get(0));
        }
      }

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                duke J. Duke (Inactive)
              • Votes:
                0 Vote for this issue
                Watchers:
                1 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Imported: