package graphics.api.control; import javafx.event.EventHandler; import javafx.beans.property.*; import javafx.application.Application; import javafx.stage.Stage; import javafx.scene.Scene; import javafx.scene.Group; import javafx.beans.property.IntegerProperty; import javafx.beans.property.StringProperty; import javafx.scene.input.KeyEvent; import javafx.scene.input.KeyCode; import javafx.scene.control.*; import javafx.scene.layout.*; public class TextBoxCannotbind extends Application { boolean flag = true; IntegerProperty columns = new SimpleIntegerProperty(5); StringProperty text = new SimpleStringProperty("12345"); TextField TextBox_a = new TextField(); Stage stage; Scene scene; FlowPane layout = new FlowPane(); public static void main(String[] args) { TextBoxCannotbind.launch(args); } @Override public void start(Stage stage) throws Exception { float h = 400; float w = 400; TextBox_a.textProperty().bind(text); TextBox_a.prefColumnCountProperty().bind(columns); TextBox_a.setEditable(false); TextBox_a.setOnKeyPressed(new EventHandler() { @Override public void handle(KeyEvent e) { if (e.getCode().equals(KeyCode.LEFT)) { if (flag) { flag = false; text.setValue("123456789012"); columns.setValue(12); } else { flag = true; text.setValue("12345"); columns.setValue(5); } layout.getChildren().clear(); layout.getChildren().addAll(TextBox_a); ((Group) scene.getRoot()).getChildren().clear(); ((Group) scene.getRoot()).getChildren().addAll(layout); } } }); layout.getChildren().clear(); layout.getChildren().addAll(TextBox_a); stage = new Stage(); scene = new Scene(new Group(), w, h); ((Group) scene.getRoot()).getChildren().clear(); ((Group) scene.getRoot()).getChildren().addAll(layout); stage.setScene(scene); TextBox_a.requestFocus(); stage.setVisible(true); } }