简体   繁体   中英

JButton Icon Change

I have JXButton[8][10](extends JButton) which each hold an Icon[2] IcAr in a gridLayout() .

Icon[1] is always the same icon while Icon[0] changes according to what i click.

For instance i click at JXButton[1][3] -> then i click at JXButton[4][7] -> meaning JXButton[4][7].setIcon(JXButton[1][3].getIcon) .

These are the IcAr[0] icons that each hold at the start.

When i finish this move i need some of the icons to change to IcAr[1] .

When i make a move again i need now some of the icons to change back to IcAr[0] .

With what i have tried so far i get unexplained behaviour. (Sometimes it works,sometimes it makes the icons null,sometimes it doesnt change the ones i need changed).

If someone is able to write a simple example on how that should be done that thinks it might help i would appreciate it. Any insights would be helpfull too.

Have you tried:

jbutton.setIcon(image);

Where jbutton is your jbutton and image is the new ImageIcon.

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