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

ComboBox action event not fired when setting selected index before visible

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P3 P3
    • None
    • 8u40
    • javafx
    • x86
    • windows_8

      FULL PRODUCT VERSION :
      java version "1.8.0_45"
      Java(TM) SE Runtime Environment (build 1.8.0_45-b15)
      Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      Windows 8.1 Pro 64-bit (6.3, Build 9600)

      A DESCRIPTION OF THE PROBLEM :
      When setting the index of the selected item in the ComboBox, the onAction event is not called.

      REGRESSION. Last worked in version 8u25

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1 - Create a new JavaFX fxml project
      2 - Add ComboBox, add an Id and an onAction
      3 - In the fxml controller, add three items to the comboBox.
      4 - Select last index
      5 - Have a System.out to print something to the console in the onAction method.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The System.out should print out when the even it fired.
      ACTUAL -
      Nothing is written out due to the event is not being fired.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      Controller:

      public class FXMLDocumentController implements Initializable {
          @FXML
          private ComboBox<String> comboBox;

          /**
           * Initializes the controller class.
           */
          @Override
          public void initialize(URL url, ResourceBundle rb) {
              
              ArrayList<String> modesDefault = new ArrayList<>();
              modesDefault.add("Backup");
              modesDefault.add("Burn");
              modesDefault.add("Erase");
              comboBox.getItems().addAll(FXCollections.observableList(modesDefault));
              comboBox.getSelectionModel().selectFirst();
              comboBox.getSelectionModel().selectLast();
          }

          @FXML
          private void onAction_ComboBox(ActionEvent event) {
              System.out.println("onAction is fired!");
          }
      }



      FXML:

      <?xml version="1.0" encoding="UTF-8"?>

      <?import java.lang.*?>
      <?import java.util.*?>
      <?import javafx.scene.*?>
      <?import javafx.scene.control.*?>
      <?import javafx.scene.layout.*?>

      <AnchorPane id="AnchorPane" prefHeight="200" prefWidth="320" xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/8" fx:controller="test.comboboxcalled.FXMLDocumentController">
         <children>
            <ComboBox fx:id="comboBox" layoutX="75.0" layoutY="75.0" onAction="#onAction_ComboBox" prefWidth="150.0" />
         </children>
      </AnchorPane>
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Call the onAction manually each time an index is set.

      SUPPORT :
      YES

            leifs Leif Samuelsson (Inactive)
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: