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

问题描述 投票:11回答:3

我正在使用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

java windows javafx installer javafx-gradle-plugin
3个回答
5
投票

记录这个here的公开拉取请求

它说:

Customize Icons

要自定义本机包中使用的图标,您必须提供相应包的图标。图标必须遵循文件名约定才能被选中。

提示:将verbose设置为true,以记录从deploy目录中拾取的文件。

特别是对于Microsoft Windows:

视窗

图标位置:src/main/deploy/windows

对于Windows,您可以提供两个不同的图标。

  • 应用程序图标
  • setup icon - 安装程序的图标

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

尽管它在那里说了,正确的路径是src/main/deploy/packages/windows,如adjusted-launcher-icon example所示。


2
投票

也许您的图像路径("/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软件包是否具有跨平台风格的开始菜单集成,停靠和托盘图标,菜单栏集成和单击图标。为此,如果您计划分发应用程序,则需要在输出文件夹中对文件进行签名,使用here in 7.3.5声明signtool.exe

现在你需要在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', '[email protected]', '[email protected]', '[email protected]']
        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 = '[email protected]'
        kind = 'selected'
        width = 16
        height = 16
        scale = 1
    }
}

1
投票

这里记录了如何做到这一点的一般程序:https://github.com/BilledTrain380/javafx-gradle-plugin/blob/648acafa7198e9bd7cf1a2ef933456ce5e0b65f9/README.md#customize-icons但最近我遇到了最新版本的打包程序(实际上是ant任务)的问题。似乎有些东西被破坏了,因为它适用于旧的(Java 8)版本的打包器,但不适用于最近的版本。然而,我能够通过明确指定来使其工作

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

在fx:deploy部分中。我不知道在Gradle中是怎么做到的,因为我使用了蚂蚁,但你应该能够找到它。在旧版本的打包机中,这不是必需的。

© www.soinside.com 2019 - 2024. All rights reserved.