FlowPane将node从左到右水平或从上到下垂直放置在pane中,分别用到Orientation.HORIZONTAL和Orientation.VERTICAL方法。
我们也可以设置node之间的距离,下面的例子演示FlowPane的用法:
import javafx.application.Application; import javafx.geometry.Insets; import javafx.scene.Scene; import javafx.scene.control.Label; import javafx.scene.control.TextField; import javafx.scene.layout.FlowPane; import javafx.stage.Stage; public class ShowFlowPane extends Application { @Override // Override the start method in the Application class public void start(Stage primaryStage) { // Create a pane and set its properties FlowPane pane = new FlowPane(); pane.setPadding(new Insets(11,12,13,14)); pane.setHgap(5); pane.setVgap(5); // Place nodes in the pane pane.getChildren().addAll(new Label("First Name:"), new TextField(), new Label("MI:")); TextField tfMi = new TextField(); tfMi.setPrefColumnCount(1); pane.getChildren().addAll(tfMi, new Label("Last Name:"),new TextField()); // Create a scene and place it in the stage Scene scene = new Scene(pane, 200,250); primaryStage.setTitle("ShowFlowPane");// Set the stage title primaryStage.setScene(scene);// Place the scene in the stage primaryStage.show();// Display the stage } }
说明:
1、本代码运行的结果如下:
2、Insets对象确定pane边界的距离,如下图所示:
3、tfMi.setPrefColumnCount(1)将MI text field优选的列数设为1。
冯斌:JavaFx实例(七)“ShowFlowPane”,布布扣,bubuko.com
原文:http://fengbin8606.blog.51cto.com/8840305/1423613