Search code examples
javafor-loopjavafxgridpanetetris

Creating a loop for column & row constraints with JavaFX


For my highscore window I have 20 nodes inside a gridpane (20 labels). Now I want the gridpane to be as big as the window itself which is 450 x 450, and I was planning to do this by adding column & row constraints.

This is what I tried, but got a NullPointerException.

private ColumnConstraints[] columnConstraintses;
private RowConstraints[] rowConstraintses;

for (int i = 0 ; i < 10 ; i++) {
        columnConstraintses[i] = new ColumnConstraints(40);
        rowConstraintses[i] = new RowConstraints(40);
    }

Solution

  • if you define an array you have to initiate it and set a size.

    private ColumnConstraints[] columnConstraintses = new ColumnConstraints[10];
    private RowConstraints[] rowConstraintses = RowConstraints[10];