/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package fxmlteste; import javafx.application.Application; import javafx.beans.property.SimpleStringProperty; import javafx.beans.property.StringProperty; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.fxml.FXMLLoader; import javafx.scene.Parent; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.TextField; import javafx.scene.layout.VBox; import javafx.stage.Stage; /** * * @author Giovanni */ public class BindBidiTeste extends Application { public static void main(String[] args) { Application.launch(BindBidiTeste.class, args); } SimpleStringProperty property = new SimpleStringProperty(); @Override public void start(Stage primaryStage) throws Exception { TextField t = new TextField(); t.textProperty().bindBidirectional(property); VBox root = new VBox(); root.getChildren().addAll(t); Button button = new Button("Button"); Button button2 = new Button("Button2"); button.setOnAction(new EventHandler() { @Override public void handle(ActionEvent arg0) { property.set("Texto"); } }); button2.setOnAction(new EventHandler() { @Override public void handle(ActionEvent arg0) { System.out.println(property.get()); } }); root.getChildren().addAll(button, button2); primaryStage.setScene(new Scene(root, 300, 100)); primaryStage.show(); } }