I am trying to get graphical resources to display in the GUI that I am developing, but it is difficult for me to display them. I came across other questions about loading resources like java-swing-displaying-images-from-within-a-jar and images-will-not-work-in-a-jar-file , but they do not work for me.
My problem seems to coincide with the first link where the images appear when starting from Eclipse and do not appear when starting from the command line using Jars. However, the solution of these issues does not lead to the appearance of images.
Code for loading resources:
public class R {
public static final String resourcePackage = "path/to/image/package";
public static String png(String resource) {
return String.format("%s/png/%s", resourcePackage, resource);
}
public static ResizableIcon resizableIcon(String resource) {
return ImageWrapperResizableIcon.getIcon(R.class.getClassLoader()
.getResourceAsStream(resource), new Dimension(48, 48));
}
}
I call it when creating a GUI
JCommandButton connect = new JCommandButton(i18ln.getString("ports"),
R.resizableIcon(R.png("serial-port-32x32.png")));
, , R.class.getClassLoader().getResourceAsStream sun.net.www.protocol.jar.JarURLConnection$JarURLInputStream.
. , , . ?
FYI: , , Flamingo .
EDIT: Stefan
src/
main/
java/
com.company.project (packages)
R.java
MyGui.java
resources/
com.company.project (packages)
.png (package)
serial-port-32x32.png
(more images)
.i18ln (package)
MyGui.properties
, , , . , , . - , ?
UPDATE:
Jar Eclipse , . Jar, Gradle, . , - -, Eclipse Jar, Gradle Jar. Gradle .