JavaFX TextField set preferred height/width

Description

JavaFX TextField set preferred height/width


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 {
  @Override//w w  w . j a va2s  . c o m
  public void start(Stage primaryStage) {    
    double WIDTH = 500;
    double HEIGHT = 500;
    
    GridPane pane = new GridPane();
        
    for (int i = 0; i < 10; i++) { 
      for (int j = 0; j < 10; j++) {
        TextField tf = new TextField((int)(Math.random() + 0.5) + "");  
        tf.setPrefColumnCount(1);
        tf.setAlignment(Pos.CENTER);
        // Set a large preferred width and height to occupy the entire grid pane
        tf.setPrefWidth(400); 
        tf.setPrefHeight(400);
        tf.setAlignment(Pos.CENTER);
        pane.add(tf, j, i);
      }
    }
        

    Scene scene = new Scene(pane, WIDTH, HEIGHT);
    primaryStage.setTitle("Exercise14_08");
    primaryStage.setScene(scene);
    primaryStage.show();
  }


  public static void main(String[] args) {
    launch(args);
  }
} 



PreviousNext

Related