Reputation: 29
So I'd like to fill in 50 buttons with icons, the way I tried doing this was:
String table1[][] = new String [5][10];
for(int i = 0; i<5; i++){
for(int j = 0; j<10; j++){
table1[i][j] = "W";
}
}
String table2[][] = new String [5][10];
for(int i = 0; i<5; i++){
for(int j = 0; j<10; j++){
if(i<1){
table2[i][j] = "jButton"+j;
}else{
table2[i][j] = "jButton"+i+""+j;
}
}
}
for(int i = 0; i<5; i++){
for(int j = 0; j<10; j++){
if(table2[i][j].equals("B")) table2[i][j].setIcon.. /* code 2 set icon 2 long
}
}
So I filled in a second table with jButton names and then tried calling it like: table2[i][j].setIcon, what is the correct way of going about this?
Upvotes: 2
Views: 139
Reputation: 20065
You are using arrays of String and then call setIcon on a String...
Replace your String array with a JButton array.
Upvotes: 4