📅  最后修改于: 2020-10-14 06:00:15             🧑  作者: Mango
FlowPane布局窗格将流中的节点组织起来,并包裹在流窗格的边界处。水平流窗格将节点排成一排,并根据流窗格的宽度对其进行包装。垂直流窗格将节点排列成一列,并根据流窗格的高度将它们包裹起来。 FlowPane布局由javafx.scene.layout.FlowPane类表示。我们只需要实例化此类即可创建流窗格布局。
下表中描述了该类的各种属性。
Property | Description | Setter Methods |
---|---|---|
alignment | The overall alignment of the flowpane’s content. | setAlignment(Pos value) |
columnHalignment | The horizontal alignment of nodes within the columns. | setColumnHalignment(HPos Value) |
hgap | Horizontal gap between the columns. | setHgap(Double value) |
orientation | Orientation of the flowpane | setOrientation(Orientation value) |
prefWrapLength | The preferred height or width where content should wrap in the horizontal or vertical flowpane. | setPrefWrapLength(double value) |
rowValignment | The vertical alignment of the nodes within the rows. | setRowValignment(VPos value) |
vgap | The vertical gap among the rows | setVgap(Double value) |
该类中有以下8个构造函数。
package application;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.layout.FlowPane;
import javafx.stage.Stage;
public class FlowPaneTest extends Application {
@Override
public void start(Stage primaryStage) {
primaryStage.setTitle("FlowPane Example");
FlowPane root = new FlowPane();
root.setVgap(6);
root.setHgap(5);
root.setPrefWrapLength(250);
root.getChildren().add(new Button("Start"));
root.getChildren().add(new Button("Stop"));
root.getChildren().add(new Button("Reset"));
Scene scene = new Scene(root,300,200);
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
输出: