JavaFX TextField set text alignment
import javafx.application.Application; import javafx.geometry.Pos; import javafx.scene.Scene; import javafx.scene.control.TextField; import javafx.scene.layout.GridPane; import javafx.stage.Stage; public class Main extends Application { public void start(Stage primaryStage) { GridPane pane = new BinaryPane(5); Scene scene = new Scene(pane, 400, 400); primaryStage.setScene(scene);/*from w w w.j a va 2 s .c om*/ primaryStage.setTitle("Checkerboard"); primaryStage.setMinHeight(400); primaryStage.setMinWidth(400); primaryStage.show(); } public static void main(String[] args) { Application.launch(args); } } class BinaryPane extends GridPane { BinaryPane(int n) { for (int col = 0; col < n; col++) { for (int row = 0; row < n; row++) { int random = (int) (Math.random() * 2); String binary = (random == 0) ? "0" : "1"; TextField textField = new TextField(binary); textField.setPrefColumnCount(1); textField.setAlignment(Pos.CENTER); textField.setEditable(false); add(textField, col, row); } } } }