Hi. I like to have a menu in my app. For instance...
# compose-desktop
m
Hi. I like to have a menu in my app. For instance this is a part of that example coding:
Copy code
Menu("File", mnemonic = 'F') {
     Item("Copy", onClick = { action = "Last action: Copy" }, shortcut = KeyShortcut(Key.C, ctrl = true))
     Item("Paste", onClick = { action = "Last action: Paste" }, shortcut = KeyShortcut(Key.V, ctrl = true))
}
This all works in my, including shortcuts and mnemonics. I know like to add a "listener" to each Item, so when the item gets the focus (but the user hasn't clicked on the item) a "preview" action is triggered. The reason is: the user can select different background images per item. By navigating through the menu the app should immediately show each background image as soon as an Item gets the focus (in Swing I would listen for "isArmed"). However, first when a item is clicked the background image is really set as new background image. The desktop tutorials shows how to add PoinerEvents (->https://github.com/JetBrains/compose-jb/tree/2af56d8cbf85d0530b2849545aba65b8668f0f3c/tutorials/Mouse_Events#mouse-enter-listeners). However, I don't see a modifier parameter I can pass to "Item". How can I add a PointerEvent/Listener to an Item?
d
Interesting question. I think it's not possible for now in Compose for Desktop as is. But, you can use JVM-specific API to achieve this: https://docs.oracle.com/javase/8/docs/api/java/awt/MenuItem.html
m
Thanks for the answer. Is it possible to get a reference to the awt.MenuItem? If so, then I could actually use that to add listeners. However, I just started learning Compose, hence I don't know how to get the underlying components. Well, this is just a bonus feature for the program - the program works just fine without this "preview background image" feature 🙂 Maybe I will add it later.