简体   繁体   中英

Filling jButtons with icons

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?

You are using arrays of String and then call setIcon on a String...

Replace your String array with a JButton array.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM