JetBrains / compose-multiplatform

Compose Multiplatform, a modern UI framework for Kotlin that makes building performant and beautiful user interfaces easy and enjoyable.
https://jetbrains.com/lp/compose-multiplatform
Apache License 2.0
15.27k stars 1.11k forks source link

ContextMenuArea not working with SwingPanel #4915

Closed sal0max closed 3 weeks ago

sal0max commented 4 weeks ago

Describe the bug I tried to add a ContextMenuArea around a SwingPanel and to catch right clicks.

Affected platforms

Versions

To Reproduce Steps to reproduce the behavior:

  1. Run this code snippet:
    ContextMenuArea(
       items = {
       listOf(
           ContextMenuItem("User-defined Action") { },
           ContextMenuItem("Another user-defined action") { }
       )
    }) {
       SwingPanel(
           modifier = Modifier.fillMaxSize(),
           factory = { JTextField() }
       )
    }
  2. Right-click inside the JTextField
  3. No popup will open

Expected behavior A popup should appear

MatkovIvan commented 3 weeks ago

Things in this case are complicated. The two main problem areas are:

  1. Draw something above SwingPanel
  2. Intercept input above SwingPanel

(1) is solved by https://github.com/JetBrains/compose-multiplatform-core/pull/915 but available only under a flag due to some issues. (2) with (1) in should work as-is on WIndows, but for macOS requires a workaround to redispatch Swing/AWT events to Compose is requried

Summarizing all points above it will be something like this - https://gist.github.com/MatkovIvan/11e08183b80f3a31b218a093a4ce2a9d

So it's possible to do things in this way, but I'd recommend avoid such situation if possible. Closing since it's already tracked in a couple of issues and I provided a way how to solve the problem