个性化阅读
专注于IT技术分析

JavaFX GridPane

GridPane布局窗格允许我们在多个行和列中添加多个节点。它被视为行和列的灵活网格, 可以在网格的任何单元中放置节点。它由javafx.scence.layout.GridPane类表示。我们只需要实例化此类即可实现GridPane。

物产

下表中给出了类的属性及其设置方法。

属性 描述 设置方法
alignment 表示GridPane中网格的对齐方式。 setAlignment(Pos value)
gridLinesVisible 此属性用于调试。通过将此属性设置为true, 可以显示行以显示gidpane的行和列。 setGridLinesVisible(Boolean value)
hgap 列之间的水平间隙 setHgap(Double value)
vgap 行之间的垂直间隙 setVgap(Double value)

建设者

该类仅包含下面给出的一个构造函数。

  • Public GridPane():使用0 hgap / vgap创建一个网格窗格。

例:

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);
	}
	
}

输出:

JavaFX GridPane输出
赞(0)
未经允许不得转载:srcmini » JavaFX GridPane

相关推荐

评论 抢沙发

评论前必须登录!