Howto add an icon to a button using IntelliJIDEA

Hello, I am new to IntelliJIDEA so excuse the simple question. In short, I have dropped a JButton on a panel and set the properties of the button using the UI Designer. There is a property where you can add an image icon. I navigate to the path of the "ico" file and select the icon. The path remains highlighted in RED and when I run the program I get an exception "at javax.swing.ImageIcon.]]>(" I tried setting it to a jpg file, but the same results.

Thanks for your help in advance.


Comment actions Permalink

Window ico files are not supported. Use a png file instead.

Comment actions Permalink

Thanks Tom, but as my Friday luck would have it, that did not work either. I have a png image that is 64x64 which I am using, or attempting to use as my icon. Still the same results, (same exception and text in red). Other ideas?

To recap, I am trying to add an icon to a button.



Comment actions Permalink

Maybe it would help if you could tell what exact exception occurred?

Comment actions Permalink

Sure, that may help, sorry. Here it is.

Exception in thread "main" java.lang.NullPointerException
at javax.swing.ImageIcon.( at LSX2000.MainScreen.$$$setupUI$$$( at LSX2000.MainScreen.]]>(
at LSX2000.MainProgram.main(
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(
at sun.reflect.DelegatingMethodAccessorImpl.invoke(
at java.lang.reflect.Method.invoke(
at com.intellij.rt.execution.application.AppMain.main(


Please sign in to leave a comment.