有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java如何在JavaFX中设置应用程序安装程序图标?

我正在使用JavaFX-Gradle-plugin构建可分发的二进制文件和JavaFX应用程序的安装程序。当我的应用程序运行时,我可以这样设置图标:

stage.getIcons().add(new Image(this.getClass().getResourceAsStream("/isotype.png")));

正确设置正在运行的应用程序的图标:

enter image description here

以及任务栏:

enter image description here

但是如何设置“开始”菜单的图标:

enter image description here

以及其他可能的地方:

enter image description here


共 (4) 个答案

  1. # 1 楼答案

    有一个记录此here的打开拉取请求

    它说:

    Customize Icons

    To customize the icons used in a native bundle, you have to provide the icons for the appropriate bundle. The icons must follow the file name convention in order to get picked up.

    Tip: Set the verbose setting to true, to have log which files are picked up from your deploy directory.

    尤其是对于Microsoft Windows:

    Windows

    Icon location: src/main/deploy/windows

    For Windows you can provide two different icons.

    • application icon
    • setup icon - the icon of the installer

    | Type | Filename | | :---------------- |:------------------------- | | .exe icon | \<appName>.ico | | setup exe icon | \<appName>-setup-icon.bmp |

    不管上面怎么说,正确的路径是src/main/deploy/packages/windows,如adjusted-launcher-icon example所示

  2. # 2 楼答案

    此处记录了如何执行此操作的一般程序: https://github.com/BilledTrain380/javafx-gradle-plugin/blob/648acafa7198e9bd7cf1a2ef933456ce5e0b65f9/README.md#customize-icons 但最近我在最新版本的打包机(实际上是ant任务)上遇到了问题,无法让它正常工作。有些东西似乎被破坏了,因为它适用于较旧(Java8)版本的packager,但不适用于最新版本。但是,我能够通过明确指定

    <fx:bundleArgument arg="icon" value="package/macosx/myapp.icns"/>
    

    在fx:deploy部分中。我不知道在Gradle是怎么做到的,因为我用了ant,但你们应该能找到答案。在旧版本的分装机中,这是不必要的

  3. # 3 楼答案

    可能图像的路径("/isotype.png")不正确。从下面的选项中选择一种方法以提供正确的路径。如果存储了图标图像:

    • 在文件夹(例如图像)中,然后使用此路径"/images/isotype.png",如下所示:

      stage.getIcons().add(
            new Image(this.getClass().getResourceAsStream("/images/isotype.png")));
      
    • 在包目录中,然后使用此路径"isotype.png",如下所示:

      stage.getIcons().add(new Image(this.getClass().getResourceAsStream("isotype.png")));
      
    • 在文件夹结构中,然后使用此路径"../images/isotype.png",如下所示:

      stage.getIcons().add(
            new Image(this.getClass().getResourceAsStream("../images/isotype.png"")));
      

    更新:

    您必须看一下A guide to the Gradle JavaFX Plugin,它描述了Javafx包具有跨平台的功能,如开始菜单集成、停靠和托盘图标、菜单栏集成和单击图标。因此,如果您计划分发应用程序,则必须对输出文件夹中的文件进行签名,并使用signtool.exe声明here in 7.3.5

    现在,您必须将build.gradle中的一些(图标)配置选项设置为:

    javafx {
        appID 'SampleApp'
        appName 'Sample Application'
        mainClass 'com.example.sample.Main'
    
        jvmArgs = ['-XX:+AggressiveOpts', '-XX:CompileThreshold=1']
        systemProperties = [ 'prism.disableRegionCaching':'true' ]
        arguments = ['-l', '--fast']
    
        embedLauncher = false
    
        // deploy/info attributes
        category = 'Demos'
        copyright = 'Copyright (c) 2013 Acme'
        description = 'This is a sample configuration, it is not real.'
        licenseType = 'Apache 2.0'
        vendor = 'Acme'
        installSystemWide = true
        menu = true
        shortcut = true
    
        // app icons
        icons {
            shortcut = ['shortcut-16.png', 'shortcut-32.png', 'shortcut-128.png', 'shortcut-256.png', 'shortcut-16@2x.png', 'shortcut-32@2x.png', 'shortcut-128@2x.png']
            volume = 'javafx-icon.png'
            setup = 'javafx-icon.png'
        }
    
        // applet and webstart stuff
        debugKey {
            alias = 'debugKey'
            //keyPass = 'password' // provide via command line
            keyStore = file('~/keys/debug.jks')
            //storePass = 'password'  // provide via command line
        }
        releaseKey {
            alias = 'production'
            //keyPass = 'password' // provide via command line
            keyStore = file('/Volumes/ProdThumbDrive/production.jks')
            //storePass = 'password'  // provide via command line
        }
        signingMode 'release'
    
        width = 800
        height = 600
        embedJNLP = false
        codebase = 'http://example.com/bogus/JNLP/Codebase'
    
        // arbitrary jnlp icons
        icon {
            href = 'src/main/resources/javafx-icon.png'
            kind = 'splash'
            width = 128
            height = 128
        }
        icon {
            href = 'shortcut-32@2x.png'
            kind = 'selected'
            width = 16
            height = 16
            scale = 1
        }
    }
    
  4. # 4 楼答案

    如果您正在使用ant构建或工件来构建javafx应用程序,那么下面的文章可能会有所帮助

    https://flaironix.com/2019/09/18/adding-custom-icon-for-javafx-application-exe-file-in-intelije/

    在工件中使用此选项标记

    <option name="icons">
        <JavaFxApplicationIcons>
        <option name="linuxIcon" value="$PROJECT_DIR$/src/Controller/logo.png" />
        <option name="windowsIcon" value="$PROJECT_DIR$/src/Controller/logo.ico"/>
       </JavaFxApplicationIcons>
    </option>