下面列出了javafx.scene.control.TextField#setAlignment ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public FieldCell(Field<?> value, int index) {
getStyleClass().add("field-cell");
getStyleClass().add("field-cell-" + (index % 2 == 0 ? "even" : "odd"));
this.value = value;
textField = new TextField();
getChildren().addAll(new Label(value.getType().toString()), textField);
textField.textProperty().addListener((a, o, n) -> onInput(n));
textField.setAlignment(Pos.CENTER);
}
private TextField createDistanceTextField(double x, double y) {
final TextField distanceTextField = new TextField();
distanceTextField.setPromptText("(mm)");
distanceTextField.setLayoutX(x);
distanceTextField.setLayoutY(y);
distanceTextField.setPrefWidth(75);
distanceTextField.setAlignment(Pos.CENTER);
distanceTextField.textProperty().addListener(new NumberOnlyChangeListener(distanceTextField));
return distanceTextField;
}
@Override // Override the start method in the Application class
public void start(Stage primaryStage) {
SierpinskiTrianglePane trianglePane = new SierpinskiTrianglePane();
TextField tfOrder = new TextField();
tfOrder.setOnAction(
e -> trianglePane.setOrder(Integer.parseInt(tfOrder.getText())));
tfOrder.setPrefColumnCount(4);
tfOrder.setAlignment(Pos.BOTTOM_RIGHT);
// Pane to hold label, text field, and a button
HBox hBox = new HBox(10);
hBox.getChildren().addAll(new Label("Enter an order: "), tfOrder);
hBox.setAlignment(Pos.CENTER);
BorderPane borderPane = new BorderPane();
borderPane.setCenter(trianglePane);
borderPane.setBottom(hBox);
// Create a scene and place it in the stage
Scene scene = new Scene(borderPane, 200, 210);
primaryStage.setTitle("Exercise_18_36"); // Set the stage title
primaryStage.setScene(scene); // Place the scene in the stage
primaryStage.show(); // Display the stage
scene.widthProperty().addListener(ov -> trianglePane.paint());
scene.heightProperty().addListener(ov -> trianglePane.paint());
}