سؤال

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