Styling Compose for Desktop Tray Composable
Asked Answered
A

1

11

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.

Adalia answered 3/11, 2022 at 0:53 Comment(1)
Windows is a similar situation, my own application looks plain, similar to what you see on Linux. But their application's menu looks more like the native Windows ones. (For some definition of native. I guess it looks like a Swing menu with Windows L&F?)Receptive
C
0

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)
Conjurer answered 5/2 at 8:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.