java用标签填充GridPane
我有了这个构造函数,我正试图用标签填充网格窗格。 我碰上了一堵墙,不知道出了什么事。 我需要在一行中创建13个标签
建造商:
public class Labels {
@FXML
GridPane gridPane = new GridPane();
public Labels(String labelname, int columnIndex, int rowIndex) {
Label label = new Label();
gridPane.setColumnIndex(label, columnIndex);
gridPane.setRowIndex(label, rowIndex);
label.setId(labelname+columnIndex);
label.setVisible(true);
label.setText("test");
}
}
环路控制器:
for(int i2=0; i2<13; i2++){
Labels labels = new Labels("label", i2, 3);
}
# 1 楼答案
您没有将
Label
添加到GridPane
。此外,对每个Label
使用新的GridPane
,并且永远不要在任何地方使用这些GridPane
# 2 楼答案
(总是发mcve)