HeaderBar consuming click with DRAGGABLE_SUBTREE (when focus lost and gained)
Cormac Redmond
credmond at certak.com
Thu Jan 1 22:53:56 UTC 2026
Hi,
I've noticed this behaviour as follows with a HeaderBar stage and MenuBar.
If you make the JFX window lose focus, but still keep it visible, note the
Menu items are responding to mouse hovers. But the first click is always
ignored (i.e., no menu shown). This can be more frustrating than it may
sound, when dealing with a lot of popups and secondary window hopping, etc.
I assume this is not limited to MenuBar either.
Example and code below. I will browse to Notepad to lose focus. The red
circle you see is a click, see how it requires two clicks for the menu to
appear when coming back from Notepad. Note this is not the behaviour for
"Normal Menu", a menu not inside HeaderBar.
[image: menu_focus.gif]
public class MenuClickIssue extends Application {
public static void main(String[] args) { launch(args); }
@Override
public void start(Stage primaryStage) {
MenuBar hbMenu = getMenuBar("HeaderBar Menu");
HeaderBar.setDragType(hbMenu, HeaderDragType.DRAGGABLE_SUBTREE);
Region region = new Region();
HBox.setHgrow(region, Priority.ALWAYS);
HeaderBar.setDragType(region, HeaderDragType.DRAGGABLE_SUBTREE);
HBox menuHbox = new HBox(hbMenu, region);
final HeaderBar headerBar = new HeaderBar();
headerBar.setCenter(menuHbox);
primaryStage.initStyle(StageStyle.EXTENDED);
primaryStage.setScene(new Scene(new BorderPane(getMenuBar("Normal
Menu"), headerBar, null, null, null), 600, 400));
primaryStage.show();
}
private MenuBar getMenuBar(String title) {
MenuBar hbMenu = new MenuBar();
final Menu file = new Menu(title);
file.getItems().addAll(new Menu("New"), new Menu("Open"));
hbMenu.getMenus().addAll(file, new Menu("Edit"));
return hbMenu;
}
}
Kind Regards,
Cormac
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/openjfx-dev/attachments/20260101/caacf8ed/attachment-0001.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: menu_focus.gif
Type: image/gif
Size: 213715 bytes
Desc: not available
URL: <https://mail.openjdk.org/pipermail/openjfx-dev/attachments/20260101/caacf8ed/menu_focus-0001.gif>
More information about the openjfx-dev
mailing list