'JavaFX popup blocks first mousePress on the background

I have a popup on button press
When I press a button the popup shows up.

    public class Main extends Application {

    @Override
    public void start(Stage primaryStage) throws Exception {

        StackPane root = new StackPane();

        root.setPrefWidth(200);
        root.setPrefHeight(200);
        Button btn = new Button("Press");

        root.getChildren().add(btn);

        root.setOnMouseDragged(e-> System.out.println("draaaag"));
        root.setOnMousePressed(e-> System.out.println("PRESSED"));
        root.setOnMouseReleased(e-> System.out.println("RELEASED !!!!!!!!!!!!!!!"));

        Scene scene = new Scene(root);

        Popup popup = new Popup();
        popup.getContent().add(new Label("POPUP"));
        popup.setAutoHide(true);
        popup.setAutoFix(true);

        

        btn.setOnMouseClicked(ev -> {
            popup.show(primaryStage);
        });

        primaryStage.setScene(scene);
        primaryStage.show();
    }
    
}

background have mouseDrag, mousePress and mouseRelease events.
When I open the popup and click the on the root, the popup hides as expected, but the root area notifies only mouseRelease and drag actions first, than all other actions act.

IWant to listen on mousePress on root even if the popup is showing...



Solution 1:[1]

I got the answer.
the event is consumed on auto hide
so

popup.setConsumeAutoHidingEvent(false)

It does the job.

Solution 2:[2]

Popup are managed as different window higher than the one you insert. Therefore you have to insert onMouseRelease event also to popup:

popup.getContent().get(0).setOnMouseReleased(e -> System.out.println("Popup clicked!"));

you can also add a styled Label with a different background to highlight the popup:

Label label = new Label("POPUP");
label.setStyle("-fx-background-color: grey;");
popup.getContent().add(label);
label.setOnMouseReleased(e -> System.out.println("Popup clicked!"));

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Mateusz Niedbal
Solution 2 savio99