0

I'm trying to set an Icon to my Radio Button.

ImageIcon ImIcon= new ImageIcon("icons/star.ico"); //I have tried .png too
jRadioButton1.setIcon(ImIcon); //or setSelectedIcon same resul

The only result that I get is that the original RadioButton Icon is vanishing, but the text still remains.

Why won't it show it self?

1 Answers1

2

Check the Java API for ImageIcon and you'll see that if you call the constructor with a String, it will try to create an ImageIcon with the file represented by the String path. You can't swap the file name at random, but rather it must exactly match the file name of the file found on disk. Also the path to the file needs to be found relative to the user's directory, something you can find by calling:

System.out.println(System.getProperty("user.dir"));
Hovercraft Full Of Eels
  • 283,665
  • 25
  • 256
  • 373