📅  最后修改于: 2020-10-14 06:00:04             🧑  作者: Mango
GridPane布局窗格允许我们在多个行和列中添加多个节点。它被视为行和列的灵活网格,可以在网格的任何单元中放置节点。它由javafx.scence.layout.GridPane类表示。我们只需要实例化此类即可实现GridPane。
下表提供了类的属性及其设置方法。
Property | Description | Setter Methods |
---|---|---|
alignment | Represents the alignment of the grid within the GridPane. | setAlignment(Pos value) |
gridLinesVisible | This property is intended for debugging. Lines can be displayed to show the gidpane’s rows and columns by setting this property to true. | setGridLinesVisible(Boolean value) |
hgap | Horizontal gaps among the columns | setHgap(Double value) |
vgap | Vertical gaps among the rows | setVgap(Double value) |
该类仅包含下面给出的一个构造函数。
package application;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.GridPane;
import javafx.stage.Stage;
public class Label_Test extends Application {
@Override
public void start(Stage primaryStage) throws Exception {
Label first_name=new Label("First Name");
Label last_name=new Label("Last Name");
TextField tf1=new TextField();
TextField tf2=new TextField();
Button Submit=new Button ("Submit");
GridPane root=new GridPane();
Scene scene = new Scene(root,400,200);
root.addRow(0, first_name,tf1);
root.addRow(1, last_name,tf2);
root.addRow(2, Submit);
primaryStage.setScene(scene);
primaryStage.show();
}
public static void main(String[] args) {
launch(args);
}
}
输出: