A splash screen is an excellent way to provide users with a visually engaging placeholder while your Compose for Desktop application initializes. This guide will show you how to set up a splash screen in your Compose for Desktop project using the jvmArgs configuration in your build.gradle.kts file.
splash.png
) ready in the assets folder.Ensure you have an assets folder in your project root directory. Place the splash.png
file inside this folder. The path should look like:
/project-root/assets/splash.png
build.gradle.kts
Add the nativeDistributions
configuration in your build.gradle.kts
file to set up the splash screen. Here's the updated configuration:
compose.desktop {
application {
mainClass = "MainKt"
nativeDistributions {
appResourcesRootDir.set(project.layout.projectDirectory.dir("assets"))
jvmArgs += "-splash:${'$'}APPDIR/resources/splash.png"
}
}
}
mainClass
: Specifies the entry point of your application.nativeDistributions
: Indicates where your application resources are located. By setting the appResourcesRootDir
to the assets
directory, your resources (like splash.png
) are included in the build.jvmArgs
: Configures JVM arguments to display the splash screen. The -splash
option points to the splash image location.Build and run your Compose for Desktop application. When launching, the splash screen will display until your app's main window is fully initialized.
With these steps, your Compose for Desktop application will feature a professional splash screen, enhancing the user experience while your application starts.