JCEF heavyweight popup closes too early or always stays on top

Given the following code:

//--------------- Attempt 1 ---------------
val browser = JBCefBrowser()
browser.loadHTML("<html><body><h1>Hello World</h1></body></html>")
browser.component.preferredSize = Dimension(400, 400)
val popup = JBPopupFactory.getInstance()
.createComponentPopupBuilder(browser.component, browser.component)
.setShowBorder(false)
.setShowShadow(false)
.setRequestFocus(true)
.setCancelOnWindowDeactivation(true)
.createPopup()
popup.showInFocusCenter()

 

If you click the browser that appears, it will immediately disappear. Sometimes you have to click a few times but it will immediately disappear.

You can see this behavior here:

 

I've solved this problem by using this code:

//--------------- Attempt 2 ---------------
val browser = JBCefBrowser()
browser.loadHTML("<html><body><h1>Hello World</h1></body></html>")
browser.component.preferredSize = Dimension(400, 400)
val popup = JBPopupFactory.getInstance()
.createComponentPopupBuilder(browser.component, browser.component)
.setShowBorder(false)
.setShowShadow(false)
.setRequestFocus(true)
.setCancelOnWindowDeactivation(false) //<< only difference
.createPopup()
popup.showInFocusCenter()

 

But now the popup will not close when you leave the IDE. It will close if you click somewhere in the IDE but if you minimize the IDE and click outside of the IDE, it will always remain on top of everything:

 

I've been trying for a few days to figure this out and I'm not making any progress. I don't understand why the first attempt closes when you click it and no matter what type of listeners I add I can't seem to grab an event that indicates the IDE is no longer in focus. I've added FocusListeners/WindowListeners/etc and even listening to ApplicationActivationListener events but nothing will fire once you click inside the popup.

 

I've made a tiny project for re-creating this issue: https://github.com/BFergerson/hide-heavy-popup

To make the popup appear you have use the shortcut "Control+Shift+S"

1 comment
Comment actions Permalink

Brandon,

Thanks for reporting that. Unfortunately, I was not able to reproduce any of the scenarios on

IntelliJ IDEA 2020.2 EAP (Community Edition)
Build #IC-202.5103.24, built on June 8, 2020
Runtime version: 11.0.7+10-b931.3 x86_64
VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o.
macOS 10.15.5
GC: G1 Young Generation, G1 Old Generation
Memory: 512M
Cores: 16
Non-Bundled Plugins: org.example.hide-heavy-popup

Can I ask you to file an issue on YouTrack?

0

Please sign in to leave a comment.