0

I'm following the Zetcode tutorial on Java Swing; in this section it is explained how to create a menu, including how to add icons to the various menu elements. Unfortunately, the icons do not show up when I run the code in Eclipse, despite I just reproduce the same code from there and I do not get any compile-time error. I've already tried to have a look at the Oracle tutorial but I can't understand where the problem is; maybe somebody can help me?

Community
  • 1
  • 1
Alex Reds
  • 197
  • 2
  • 4
  • 17
  • 1
    With code like `ImageIcon icon = new ImageIcon("exit.png");` I am not surprised it fails. Application resources will become embedded resources by the time of deployment, so it is wise to start accessing them as if they were, right now. An [tag:embedded-resource] must be accessed by URL rather than file. See the [info. page for embedded resource](http://stackoverflow.com/tags/embedded-resource/info) for how to form the URL. – Andrew Thompson Apr 13 '15 at 21:22
  • just to understand, I thought the icons from the tutorial were already embedded in Swing; do you mean they are not? – Alex Reds Apr 14 '15 at 09:37
  • *"I thought the icons from the tutorial were already embedded in Swing"* No. In fact, though there are a lot of images stored inside the JRE for the icons used by each Pluggable Look and Feel, I've never seen those images used in any (official) Java Tutorial code. So even the official tutorial does not use 'internal' images. That code is explicitly trying to load a `File` (which is not how it would be loaded if it were inside the JRE Jars) so would not work for those images either. – Andrew Thompson Apr 14 '15 at 09:58

0 Answers0