Java-FX MenuBar in JFrame/JFXPanel : First click not recognized

115 Views Asked by At

I want to place a JavaFX MenuBar over a JFrame (Netbeans RCP). So I have placed a JFXPanel on the JFrame and have kept the FX Menubar over that. But whenever I click the Menu (when it's not focussed), the first click doesn't work. Only the after I click twice, the Menu is shown.

[Answer / a work-around is provided in the first comment]

1

There are 1 best solutions below

0
On

Your JavaFX scene doesn't have focus until you click the first time. This is mostly because the JavaFX render loop is a completely separate thread from the Swing render loop used by the underlying NetBeans RCP. The JFXPanel only facilitates synchronization of the rendering and layout between threads, not event transfer You can typically fix this by adding focus requests to your JavaFX scene, usually at the highest level. Try adding something like:

sceneRoot.setOnMouseEntered(event -> {
     sceneRoot.requestFocus();
});

Where sceneRoot is one of your highest level JavaFX containers... like a borderpane or whatever.