3

システム トレイ アイコンの実装に関する非常に簡単なチュートリアルがあります。

問題は、Eclipse からアプリを実行するとトレイにアイコンが表示されますが、実行可能な jar ファイルをエクスポートして実行するとアイコンが表示されないことです。アプリには、同じフォルダーから正常に動作する他の画像があります。

トレイは機能しています (左クリックと右クリック) が、画像でわかるように画像が表示されません (上部に jar ファイル、下部に eclipse があります)。

欠落画像の例

なんで?ありがとう、そして私の英語でごめんなさい!

編集:私は最終的に画像にアクセスする必要がある解決策を見つけました:

Image img = Toolkit.getDefaultToolkit().getImage(MyClass.class.getResource("/images/asd.png"));
4

1 に答える 1

1

The problem is the way you include the image file. You will have to include the image in the JAR when you create it, and you will have to access the image in a different manner:

try {
    InputStream is = ClassLoader.getSystemClassLoader().getResourceAsStream("wing16.png");
    BufferedImage img = ImageIO.read(is);
}
catch (IOException e) {}

You can just used the img variable to set the image in the JAR.

Update:

Take all of your class files & images and go to command line:

jar -cvfm Test.jar Manifest.mft *.class image.png

Replace Manifest.mft with your manifest file name. Replace image.png with the image you want to show up (you can include more images if you need to)

于 2011-02-18T02:12:47.120 に答える