Ok so I use use this code to import an icon from the same file that the class is in and assign it a JLabel,

JLabel label1;
Icon iron_ore = new ImageIcon(getClass().getResource("icon_ore"));
label1 = new JLabel(iron_ore);

But what code do I have to add if I want to put the icon in a file different from witch the class is in? Thank you.

有帮助吗?

解决方案

If the image is in the package foo.bar.baz, you use

getClass().getResource("/foo/bar/baz/the-icon.png")

as explained in the javadoc, of course.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top