如何在索引为(0,0)的GridPane堆栈上修复标签?似乎忽略了我对函数的输入

问题描述 投票:1回答:1

我正在尝试使用GridPane布局在javafx中创建基本的登录屏幕。问题在于,我放在网格上的所有标签都将移至位置(0,0),似乎忽略了我的列索引和行索引的值。

我已经尝试将索引的极值放入函数调用中,并且没有任何动作。似乎忽略了我提供的任何索引,默认为(0,0)。

GridPane设置:

GridPane grid = new GridPane();
grid.setPadding(new Insets(10, 10, 10, 10));
grid.setVgap(10);
grid.setHgap(10);

该函数需要标签:

// Name label
    Label nameLabel = new Label("Username:");
    GridPane.setConstraints(grid, 0, 0);     

// Password label
   Label passLabel = new Label("Password:");
   GridPane.setConstraints(grid, 0, 1);      

将GridPane添加到场景:

grid.getChildren().addAll(nameLabel, nameInput, passLabel, passInput, loginButton);
Scene scene = new Scene(grid, 300, 200);
java javafx gridpane
1个回答
0
投票

您使用的GridPane.setConstraints();错误。代替在grid上设置约束,您应该在节点上设置约束。示例:

© www.soinside.com 2019 - 2024. All rights reserved.