You could see it on attached movie.
And you can use the next code:
import javafx.application.Application;
import javafx.event.Event;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.layout.Pane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
public class Issue3 extends Application {
public static void main(String[] args) {
launch(args);
}
final ComboBox<String> testedComboBox = new ComboBox<String>();
@Override
public void start(Stage stage) throws Exception {
Pane pane = new Pane();
pane.setPrefHeight(200);
pane.setPrefWidth(200);
pane.getChildren().add(testedComboBox);
testedComboBox.setVisibleRowCount(5);
testedComboBox.setOnAction(new EventHandler() {
public void handle(Event t) {
System.out.println(testedComboBox.getValue());
}
});
TextField tf = new TextField();
//testedComboBox.valueProperty().bindBidirectional(tf.textProperty());
testedComboBox.valueProperty().bind(tf.textProperty());
VBox vb = new VBox();
vb.getChildren().addAll(pane, tf);
Scene scene = new Scene(vb, 400, 400);
stage.setScene(scene);
stage.show();
}
}
Comment/uncomment according lines about binding to tf.textFieldProperty.
You could see difference in calling onAction on adding each symbol for bidirectional and unidirectional bindings:
bidirectional: listener is called for each symbol.
unidirectional: listener is not called.
And you can use the next code:
import javafx.application.Application;
import javafx.event.Event;
import javafx.event.EventHandler;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.layout.Pane;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
public class Issue3 extends Application {
public static void main(String[] args) {
launch(args);
}
final ComboBox<String> testedComboBox = new ComboBox<String>();
@Override
public void start(Stage stage) throws Exception {
Pane pane = new Pane();
pane.setPrefHeight(200);
pane.setPrefWidth(200);
pane.getChildren().add(testedComboBox);
testedComboBox.setVisibleRowCount(5);
testedComboBox.setOnAction(new EventHandler() {
public void handle(Event t) {
System.out.println(testedComboBox.getValue());
}
});
TextField tf = new TextField();
//testedComboBox.valueProperty().bindBidirectional(tf.textProperty());
testedComboBox.valueProperty().bind(tf.textProperty());
VBox vb = new VBox();
vb.getChildren().addAll(pane, tf);
Scene scene = new Scene(vb, 400, 400);
stage.setScene(scene);
stage.show();
}
}
Comment/uncomment according lines about binding to tf.textFieldProperty.
You could see difference in calling onAction on adding each symbol for bidirectional and unidirectional bindings:
bidirectional: listener is called for each symbol.
unidirectional: listener is not called.