문제

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