How can I display a popup menu in a JCEF panel?

2024.1+

In a com.intellij.ui.jcef.JCEFHtmlPanel, I’d like to display a popup menu.
The popup menu should display the traditional Cut, Copy and Paste items to help the user paste text into an HTML input field, for example.

I couldn’t find anything in intellij-community. The closest is the Markdown preview panel, but it’s showing an ActionGroup on top of the panel and doesn’t use anything of JCEF.

How can I show a popup menu in a JCEF panel which works with text inputs?

Thank you!

Hi Joachim!
Starting 2025.1, we did much better integration of CEF context menu into IJ platform.
You may have a look at the demo app.

CEF already offers some standard as Cut/Copy/Pase items by default. Probably you may want to remove some items from the default menu. You can do that by registering you CefContextMenuHandle and implementing onBeforeContextMenu. Pls don’t override other methods unless it’s needed and use CefContextMenuHandleAdapter base class.

If you need a solution that works smooth on earlier versions, you’d need to implement the menu popup by yourself using IJ platform swing utilities and call CefFrame#copy (paste, cut). For instance, this is how the context menu is implemented for JCEF starting 2025.1 - CefContextMenuRunner. It’s just example of how to show the context menu popup, not how to interact with JCEF. Some underlining CEF utilities are not implemented in earlier versions.