Every time you package a jar package, you will always encounter problems where images cannot be displayed. So let's take a moment to summarize,
Two methods are summarized:
1. Put the jar package and image folder in a folder, and the relative path is in this folder. For example, call the image in the image folder and directly use new imageicon ("image/logo.jpg. However, this method is not good. After all, we have packaged the program and put the picture out of the package.
2. This method is definitely to put the image folder into the jar package. Note that the image folder you want to package must be placed in the SRC folder of the project (or the folder below SRC); otherwise, you cannot enter the jar package. Then
1 ). the image folder can be placed in the same folder as the Java class file. In this way, you can directly use the relative path in the jar when packaging the file. The method is: this. getclass (). getresource ("image/logo.jpg ");
2 ). if the image folder is not in the same folder as the Java class file, you can use the absolute path in the jar. the root directory of the jar package is/(SRC can be viewed as the root directory ), if you put the image folder in the SRC folder, you can use the following method to call the image: This. getclass (). getresource ("/image/logo.jpg"); note that "/" is added here, so that the absolute path in the jar package is used.
Method reference