今まで経験したことのない問題があり、Web 上で解決策を見つけることができませんでした。メニューを印刷するためにいくつかの画像を使用する小さなプログラムがあります。
これは、画像を印刷するために使用するクラスです。
public class ViewImage extends JPanel {
private static final long serialVersionUID = 1L;
protected Image image = null;
public ViewImage(int x, int y, String path) {
this(x, y, new ImageIcon(path).getImage());
}
public ViewImage(int x, int y, Image image) {
this.image = image;
this.setBounds(x, y, image.getWidth(null), image.getHeight(null));
}
public void paintComponent(Graphics g) {
int x = ((this.getWidth() - image.getWidth(null)) / 2);
int y = ((this.getHeight() - image.getHeight(null)) / 2);
g.drawImage(image, x, y, null);
}
public void setImage(String path) {
this.image = new ImageIcon(path).getImage();
}
}
私の画像はすべてクラスパスの一部であり、次のように呼び出します。
this.getClass().getClassLoader().getResource("MyImage.png").getPath()
プログラムをjarファイルにパッケージ化し、コンソールから実行するまでは正常に動作します:
java -jar MyJar.jar
私のプログラムはうまく起動しますが、画像が印刷されません。例外もエラーも何もありません。
何がそのような行動を引き起こす可能性がありますか?