You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

JavaFX程序IDE运行时图标正常显示,打包为Jar后新添加图标不显示的问题求助

JavaFX程序IDE运行时图标正常显示,打包为Jar后新添加图标不显示的问题求助

各位大佬好,我现在正在开发一个JavaFX GUI程序,主要用来管理一批游戏和自定义控制器的协同工作。最近我做了这些改动:

  • 给GamesScreen.fxml添加了一个新按钮图标
  • 把对应的图片文件放到了项目里的对应文件夹
  • 在GameScreenController.java里加了几行按钮事件处理的代码
  • 还给GameScreen.css写了新按钮的样式

在NetBeans 17 IDE里直接点运行按钮的时候,程序完全正常,新图标显示也没问题。但当我打包成Jar文件后运行,新添加的图标就不显示了——不过有意思的是,点击图标应该在的位置,对应的功能还是能正常触发,说明逻辑部分是没问题的。

我已经排查过几个点:

  • 其他正常显示的图标,它们的图片文件和新图标在同一个文件夹里,所以路径应该没写错
  • 我试过手动删除目标输出文件夹里的图片,但运行程序时其他图标依然正常显示,这就让我更搞不懂问题出在哪了

有没有大佬能帮我分析下可能的原因?下面是相关的代码片段,需要完整文件的话我可以再提供。

GameScreenController.java 相关代码

@FXML
private void NewGameHandling(ActionEvent event) {
    currentInterpreter = new NewGameKeyboardInterpreter();
    showInterpreterDialogBox();
}

GameScreen.css 相关样式

#NewGameButton {
    -fx-background-image: url("/images/gameIcons/New_Game.png");
    -fx-background-position: center center;
    -fx-background-radius: 0;
    -fx-background-color: transparent;
    -fx-background-size: cover;
    -fx-border-width: 0;
}

#NewGameButton:hover {
    -fx-background-image: url("/images/gameIcons/New_Game_Focused.png");
}

GamesScreen.fxml 相关布局

<HBox id="gamesHBox" alignment="CENTER" layoutX="90.0" layoutY="422.0" prefHeight="288.0" prefWidth="1068.0" spacing="70.0">
    <children>
        <Button id="NewGameButton" mnemonicParsing="false" onAction="#NewGameHandling" prefHeight="152.0" prefWidth="149.0" stylesheets="@../styles/gameScreen.css" />
    </children>
</HBox>

备注:内容来源于stack exchange,提问作者N_C_Pub

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.22 15:49:41