4 Replies Latest reply: Jun 27, 2013 7:43 AM by ee75d2a6-b8f2-48a8-936b-3ee070c9d640 RSS

    Did ComboBox change in the recent JavaFX releases?

    csh
      Hi there.

      I use a ComboBox to display the gender of a person. Now recently we discovered a bug, and I am pretty sure it used to work in a previous version. I also updated my JDK recently to 7u13 ( JavaFX 2.2.5) and maybe some others did too.

      The following use case should work (and even worked in my opinion), but doesn't anymore.

      Run the code. (Gender is initialized with null)
      Click the Chose Male Button.
      Male is selected in the ComboBox.
      Click Reset.
      Click Male.
      Nothing happens! I expected that Male is again selected.

      Can someone comment on this issue please?
      import javafx.application.Application;
      import javafx.beans.property.ObjectProperty;
      import javafx.beans.property.SimpleObjectProperty;
      import javafx.collections.FXCollections;
      import javafx.event.ActionEvent;
      import javafx.event.EventHandler;
      import javafx.scene.Scene;
      import javafx.scene.control.Button;
      import javafx.scene.control.ComboBox;
      import javafx.scene.layout.VBoxBuilder;
      import javafx.stage.Stage;
      
      public class TestApp2 extends Application {
          public static void main(String[] args) {
              Application.launch();
          }
      
          private ObjectProperty<Gender> gender = new SimpleObjectProperty<Gender>();
      
          @Override
          public void start(Stage stage) throws Exception {
      
              ComboBox<Gender> comboBox = new ComboBox<Gender>();
              comboBox.setItems(FXCollections.observableArrayList(Gender.values()));
              comboBox.valueProperty().bindBidirectional(gender);
      
              Button button = new Button("Reset");
              button.setOnAction(new EventHandler<ActionEvent>() {
                  @Override
                  public void handle(ActionEvent actionEvent) {
                      gender.set(null);
                  }
              });
      
              Button buttonSetMale = new Button("Set Male");
              buttonSetMale.setOnAction(new EventHandler<ActionEvent>() {
                  @Override
                  public void handle(ActionEvent actionEvent) {
                      gender.set(Gender.MALE);
                  }
              });
      
      
              Scene scene = new Scene(VBoxBuilder.create().children(comboBox, button, buttonSetMale).build());
              stage.setScene(scene);
              stage.show();
          }
      
          public enum Gender {
              MALE,
              FEMALE,
              UNKNOWN
          }
      }