Icon wont change on a JButton
Hi, I am trying to make my JButton change icon when its clicked, here is partial sample code that im using but it is not working and id like to know why. Could anyone please help out?
Code:
img_friend = new ImageIcon("help_friend.jpg").getImage();
img_friendX = new ImageIcon("help_friendX.jpg").getImage();
btn_image_friend.setIcon(new ImageIcon(img_friend));
btn_image_friend.setMargin (new Insets (0, 0, 0, 0));
btn_image_friend.setBorder (null);
btn_image_friend.setBackground(clr_background);
btn_image_friend.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
JOptionPane.showMessageDialog(null, "Friend Button was clicked");
btn_image_friend.setIcon(new ImageIcon(img_friendX));
repaint();
}
});
When i press the friend button, it gives me the pop up and then it dissapears.