List244
asked on
Change jbutton icon
I have a jbutton where I use setIcon to try and change it, however it does not change. I have
tried Button.invalidate() Button.revalidate() and Button.repaint()... None of this has caused the
image to change. Any suggestions?
tried Button.invalidate() Button.revalidate() and Button.repaint()... None of this has caused the
image to change. Any suggestions?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Nevermind, you are right, wrong filename. I forgot to retrieve the value of the text.. I was just using the number, thanks.
ASKER
{
for(int i=0;i<5;i++)//5 texts match with 5 Dice
{
if(KE.getSource() == Text[i])
{
if (Integer.parseInt(Text[i].
Text[i].setText("" + 6);
else if (Integer.parseInt(Text[i].
Text[i].setText("" + 1);
URL Image = getClass().getResource("/"
Icon ThePic = new ImageIcon(Image);
Dice[i].setIcon(ThePic);
}
}
}
There is the code I am using to set the images based on the value of a textfield. It is identical to the code
which sets them to start with including the for-loop:
for(int i=0;i<5;i++)
{
Dice[i] = new JButton();
URL Image = getClass().getResource("/"
Icon ThePic = new ImageIcon(Image);
Dice[i].setIcon(ThePic);
}