0
osxのネイティブパッケージとしてエクスポートされたときに、fxmlファイルのタブパネル(ボタンなど)のタブの画像を読み込む際にいくつかの問題があります。FXMLとネイティブパッケージングによる画像読み込み
このコードはEclipseから起動すると正常に動作しますが、ネイティブパッケージとしてアプリケーションをエクスポートするとすべての画像が消えます。
<BorderPane stylesheets="@../my.css" xmlns="http://javafx.com/javafx/8.0.65" xmlns:fx="http://javafx.com/fxml/1" fx:controller="app.view.MainController">
<center>
<TabPane maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" tabClosingPolicy="UNAVAILABLE">
<tabs>
<Tab fx:id="projectsTab" closable="false">
<content>
<AnchorPane minHeight="0.0" minWidth="0.0">
<children>
<fx:include source="main/ProjectView.fxml" />
</children>
</AnchorPane>
</content>
<graphic>
<ImageView fitHeight="30.0" fitWidth="30.0" opacity="0.5" pickOnBounds="true" preserveRatio="true">
<image>
<Image url="@../../../resources/images/ic_list_black_48dp_1x.png" />
</image>
</ImageView>
</graphic>
</Tab>
このコードを使用すると、ネイティブパッケージとしてエクスポートされたときにも動作しますが、fxmlの方法でやりたいと思います。
private void initialize() {
projectsTab.setGraphic(createTabImage("/images/ic_list_black_48dp_2x.png"));
}
private ImageView createTabImage(String pathToImage) {
ImageView imgView = new ImageView(new Image(this.getClass().getResource(pathToImage).toExternalForm()));
imgView.setFitWidth(30);
imgView.setFitHeight(30);
imgView.setOpacity(0.5);
return imgView;
}
お勧めはありますか?
は 'resources'は通常、構築するためにエクスポートされていないソース構造でちょうどフォルダ、すなわちである必要があります。おそらく 'url =" @ ../../images/ic_list_black_48dp_1x.png "'が必要です。それでも動かない場合は、生成されたjarファイルの内容を確認してください(コマンドラインから 'jar tf jarfile.jar'を実行するだけです)。 –
それは完全に動作します。 ありがとうございました! – Kai