JavaFX TextField set Max/Min height/width

Description

JavaFX TextField set Max/Min height/width

import javafx.application.Application;
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 GridPane();
    for (int i = 0; i < 5; i++) {
      for (int j = 0; j < 5; j++) {
        TextField text = new TextField(Integer.toString((int) (Math.random() * 2)));
        text.setMinWidth(10);/*from   ww w. j  a  va2s .c  o m*/
        text.setMaxWidth(200);
        text.setMinHeight(10.0);
        text.setMaxHeight(20);
        pane.add(text, j, i);
      }
    }
    Scene scene = new Scene(pane, 400, 400);
    primaryStage.setScene(scene);
    primaryStage.setTitle("Checkerboard");
    primaryStage.setMinHeight(400);
    primaryStage.setMinWidth(400);
    primaryStage.show();
  }

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



PreviousNext

Related