[英]JButton Icon Change
I have JXButton[8][10](extends JButton)
which each hold an Icon[2] IcAr
in a gridLayout()
. 我有
JXButton[8][10](extends JButton)
,每个Icon[2] IcAr
在gridLayout()
都持有一个Icon[2] IcAr
。
Icon[1]
is always the same icon while Icon[0]
changes according to what i click. Icon[1]
始终是相同的图标,而Icon[0]
根据我单击的内容而改变。
For instance i click at JXButton[1][3]
-> then i click at JXButton[4][7]
-> meaning JXButton[4][7].setIcon(JXButton[1][3].getIcon)
. 例如,我单击
JXButton[1][3]
->然后单击JXButton[4][7]
->表示JXButton[4][7].setIcon(JXButton[1][3].getIcon)
。
These are the IcAr[0]
icons that each hold at the start. 这些是
IcAr[0]
图标,每个图标都位于开始位置。
When i finish this move i need some of the icons to change to IcAr[1]
. 完成此动作后,我需要一些图标才能更改为
IcAr[1]
。
When i make a move again i need now some of the icons to change back to IcAr[0]
. 当我再次移动时,现在需要一些图标更改回
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. 其中jbutton是您的jbutton,而image是新的ImageIcon。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.