0

I am having the following code to display a PopOver

@Override
public void start(Stage primaryStage) {
    try {

        Label lblName = new Label("Tetsing name");
        Label lblStreet = new Label("Some street name");
        Label lblCityStateZip = new Label("Some city, 111111");
        VBox vBox = new VBox(lblName, lblStreet, lblCityStateZip);

        PopOver popOver = new PopOver(vBox);

        Label label = new Label("Mouse mouse over me");

        label.setOnMouseEntered(mouseEvent -> {
            popOver.show(label, -3);
        });

        label.setOnMouseExited(mouseEvent -> {
            if (popOver.isShowing()) {
                popOver.hide();
            }
        });

        StackPane root = new StackPane();
        root.getChildren().add(label);

        Scene scene = new Scene(root, 300, 250);

        primaryStage.setTitle("Hello World!");
        primaryStage.setScene(scene);
        primaryStage.setOnCloseRequest((WindowEvent event) -> {
            System.exit(0);
        });
        primaryStage.show();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

/**
 * @param args the command line arguments
 */
public static void main(String[] args) {
    launch(args);
}

The problem is ,

  1. I want the pop-up to be displayed when mouse entered the Label - works fine.

  2. I want the pop-up to be hidden when user exits mouse from Label but not if he enters mouse in to the pop-up window.

I have added MouseEntered and MouseExited actions on Label but how can i handle the another scenario where i don't want to hide the pop-up if user enters mouse in to pop-up.

Gregor
  • 409
  • 1
  • 5
  • 12
  • 1
    One way around this is removing the `setOnMouseExited` event handler and doing `popOver.setCloseButtonEnabled(true); popOver.setHeaderAlwaysVisible(true);`. – SedJ601 Mar 17 '20 at 01:05
  • 1
    Does this answer your question? [JavaFX : Mouse events for a PopOver Window (ControlsFX)](https://stackoverflow.com/questions/57850154/javafx-mouse-events-for-a-popover-window-controlsfx) – SedJ601 Mar 17 '20 at 01:25
  • Did you create a new accout? – SedJ601 Mar 17 '20 at 01:25
  • 1
    @Sedrick If not, they copied the other question nearly verbatim... – Slaw Mar 17 '20 at 02:17
  • @Sedrick Thanks for some workaround but it hasn't solved my problem. I need the mouse over for this label. The problem is, that when is enter the popOver, then I leave the label (MouseExited) and thats why it closes the popOver. – Gregor Mar 17 '20 at 09:51
  • @Sedrick [link](https://stackoverflow.com/questions/57850154/javafx-mouse-events-for-a-popover-window-controlsfx) didnt solve the problem. They suggested only workarounds but no solution to the mouseHover problem. – Gregor Mar 17 '20 at 13:45

0 Answers0