I am assigning several buttons to a gridpane. Each button has a number as its text. I created an arrayList numbers and add numbers to it. I use collections to shuffle the numbers (I want to have a random number in each button everytime I run the program). Then I add a number to each button text using this arrayList.
I want each button to have a different number. However, right now each button in 1 column have the same number.
Any suggestions on how to fix this issue will be greatly appreciated (random assignment of the text of button).
This is my code:
Button[][] b= new Button[2][2];
List<Integer> n = new ArrayList<>();
for(int i=0; i <2; i++){
for(int j=0; j <2; j++){
b[i][j] = new Button(String.valueOf(n.get(i)));
pane.add(button[i][j], i, j);
}
}