You can use this Library : https://github.com/dorkbox/SystemTray
in your gradle file
implementation("net.java.dev.jna:jna:5.14.0")
implementation("com.dorkbox:SystemTray:4.4")
and you can use it like this in your main function :
val tray = SystemTray.get()
val resource = this::class.java.classLoader.getResource("AppIcon.png")
tray.setImage(resource)
val menu = tray.menu
// add a menu item
menu.add(MenuItem("Item 1") {
println("Item 1 selected")
})
// add a checkbox
menu.add(Checkbox("Checkbox Item") {
println("Checkbox Item: $it")
})
// add a separator
menu.add(Separator())
// add a submenu
val submenu = Menu("Submenu")
submenu.add(MenuItem("Subitem 1") {
println("Subitem 1 selected")
})
menu.add(submenu)