Styling Compose for Desktop Tray Composable

619 Views Asked by At

I've been playing around with Compose for Desktop, and I am trying to figure out how Jetbrain styled the Tray Composable. I am assuming that's what they used to build the Jetbrains Toolbox since they wrote a post about how they migrated the Toolbox to Compose for Desktop (see here).

Default Tray Jetbrains Toolbox Tray
enter image description here enter image description here

The images are from Ubuntu 22; I haven't tested Windows or Mac yet.

1

There are 1 best solutions below

0
PlusUltra On

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)