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.]]>(ImageIcon.java:138)" I tried setting it to a jpg file, but the same results.

Thanks for your help in advance.

J

4 comments
Comment actions Permalink

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

0
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.

thanks,

Jason

0
Comment actions Permalink

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

0
Comment actions Permalink

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

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

0

Please sign in to leave a comment.