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

[ComboBox] Exception when value is set, when TextField's text property is binded unidirectionally

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Not an Issue
    • Icon: P4 P4
    • 8
    • 7u6
    • javafx
    • 2.2.0-b21

      Caused by: java.lang.RuntimeException: A bound value cannot be set.
      at javafx.scene.control.TextInputControl$TextProperty.set(TextInputControl.java:971)
      at javafx.scene.control.TextInputControl.setText(TextInputControl.java:193)

      //code
      @Override
          public void start(Stage stage) throws Exception {
              final ComboBox cb = new ComboBox();
              final TextField tf = new TextField();
              
              cb.setEditable(true);
              
              Button btnBind = new Button("1. Bind text field");
              btnBind.setOnAction(new EventHandler<ActionEvent>() {

                  @Override
                  public void handle(ActionEvent t) {
                      cb.getEditor().textProperty().bind(tf.textProperty());
                  }
              });
              
              Button btn = new Button("2. Set value");
              btn.setOnAction(new EventHandler<ActionEvent>() {

                  @Override
                  public void handle(ActionEvent t) {
                      cb.setValue(1);
                  }
              });
              
              VBox vb = new VBox(10.);
              vb.getChildren().addAll(cb, tf, btnBind, btn);
              
              Scene scene = new Scene(vb, 200, 300);
              
              stage.setTitle("Bug");
              stage.setScene(scene);
              stage.show();
          }

      click button 1. Bind text field
      type any text in text field
      click button 2. Set value

            jgiles Jonathan Giles
            dzinkevi Dmitry Zinkevich (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported: