/* * Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved. */ package tests; import javafx.application.Application; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.control.*; import javafx.scene.layout.VBox; import javafx.stage.Stage; public class TextFieldIssue extends Application { @Override public void start(final Stage stage) { stage.setTitle("Sample"); Scene scene = new Scene(new Group(), 500, 500); TextField tf1 = new TextField("test"); TextField tf2 = new TextField(""); final TextField tf3 = new TextField(); Button button = new Button("Set 3rd text field to null"); button.setOnAction(new EventHandler() { @Override public void handle(ActionEvent t) { System.out.println("tf3 before setting : \"" + tf3.getText() + "\""); System.out.println("setting tf3 to null"); tf3.setText(null); } }); VBox vbox = new VBox(10); vbox.getChildren().addAll(tf1, tf2, tf3, button); Group root = (Group) scene.getRoot(); root.getChildren().clear(); root.getChildren().addAll(vbox); stage.setScene(scene); stage.show(); } /** * @param args the command line arguments */ public static void main(String[] args) { Application.launch(args); } }