Removal of Parent for Popup Menu Javafx

I have a circular popup menu with a number of buttons which launches based on the location of the mouse on the screen. I am using Java 17 and JavaFx 22.0.1. The popup works well however my issue is the the pane is annoyingly still visible and noticable when you mouse down to the taskbar in windows. Here is the core elements of the code

 @Override
    public void initialize(URL location, ResourceBundle resources) {
        popup = new Popup();
        initializeCircularMenu();
    }

    
}


private void hideMenu() {
        if (popup != null) {
            popup.hide();
        }

        // Hide using CSS visibility
        circularMenuPane.setVisible(false);
        circularMenuPane.setManaged(false);

        // Ensure the pane is removed from its parent
        StackPane stackPane = ui.getStackPane();
        if (stackPane.getChildren().contains(circularMenuPane)) {
            System.out.println("Removing circularMenuPane from parent: " + stackPane.getId());
            System.out.println("Parent before removal: " + stackPane.getChildren());
            stackPane.getChildren().remove(circularMenuPane);
            stackPane.layout();  // Force layout pass
            System.out.println("Parent after removal: " + stackPane.getChildren());
            System.out.println("Is circularMenuPane in scene graph: " + stackPane.getChildren().contains(circularMenuPane));
        }
    }

    public void showMenu(Double x, Double y, PrimaryController ui) {
        this.ui = ui;
        this.clickX = x;
        this.clickY = y;

        // Calculate the map coordinates
        Point2D point = new Point2D(x, y);
        Point mapPoint = ui.getMapView().screenToLocation(point);
        Point wgs84Point = (Point) GeometryEngine.project(mapPoint, SpatialReferences.getWgs84());
        coordinates = wgs84Point.getX() + "," + wgs84Point.getY();
        int uniqueId = createUniqueCode();

        // Set the size of the circularMenuPane
        circularMenuPane.setPrefSize(RADIUS * 2, RADIUS * 2);

        // Add the circularMenuPane to the stackPane if not already added
        StackPane stackPane = ui.getStackPane();
        if (!stackPane.getChildren().contains(circularMenuPane)) {
            System.out.println("Adding circularMenuPane to the stackPane: " + stackPane.getId());
            stackPane.getChildren().add(circularMenuPane);
        }

        circularMenuPane.setManaged(true);
        circularMenuPane.setVisible(true);

        // Set the popup content and show it
        popup.getContent().clear();
        popup.getContent().add(circularMenuPane);
        popup.setAutoHide(false);
        popup.show(ui.getPrimaryStage());

        // Adjust the popup to be centered on the click coordinates
        double paneCenterX = circularMenuPane.getPrefWidth() / 2;
        double paneCenterY = circularMenuPane.getPrefHeight() / 2;

        double offsetX = clickX - paneCenterX;
        double offsetY = clickY - paneCenterY;

        double additionalOffsetX = 45; // Based on the offset seen in previous results
        double additionalOffsetY = -100; // Based on the offset seen in previous results

        popup.setX(offsetX - additionalOffsetX);
        popup.setY(offsetY - additionalOffsetY);

        System.out.println("Click coordinates: (" + clickX + ", " + clickY + ")");
        System.out.println("Popup set to: (" + popup.getX() + ", " + popup.getY() + ")");
        System.out.println("Pane center: (" + paneCenterX + ", " + paneCenterY + ")");

        popup.getContent().get(0).setOnKeyPressed(event -> {
            if (event.getCode() == KeyCode.ESCAPE) {
                hideMenu();
            }
        });
        popup.getContent().get(0).requestFocus();
    }

    private void initializeCircularMenu() {
        circularMenuPane = new Pane();
        circularMenuPane.setId("circularMenuPane");
        circularMenuPane.setPrefSize(RADIUS * 2, RADIUS * 2);

        // Add a black circle at the center
        Circle centerCircle = new Circle(RADIUS, RADIUS, 10, Color.BLACK);
        circularMenuPane.getChildren().add(centerCircle);

        // Add menu items with labels below the icon
        for (int i = 0; i < NUM_ITEMS; i++) {
            double angle = 2 * Math.PI / NUM_ITEMS * i;
            double xButton = RADIUS + RADIUS * Math.cos(angle) - 50;
            double yButton = RADIUS + RADIUS * Math.sin(angle) - 50;

            Button button = new Button(buttonLabels[i]);
            button.setShape(new Circle(10));
            button.setMinSize(100, 100);
            button.setMaxSize(100, 100);
            button.setStyle("-fx-content-display: top; -fx-font-size: 10px;");
            button.setWrapText(true);
            button.setTextAlignment(javafx.scene.text.TextAlignment.CENTER);

            String iconPath = getIconPath(i);
            if (iconPath != null) {
                ImageView icon = new ImageView(new Image(iconPath));
                icon.setFitWidth(35);
                icon.setFitHeight(35);
                button.setGraphic(icon);
            } else {
                System.err.println("Icon not found for button: " + buttonLabels[i]);
            }

            button.setLayoutX(xButton);
            button.setLayoutY(yButton);

            final int index = i;
            button.setOnAction(event -> handleButtonClick(index));

            circularMenuPane.getChildren().add(button);
        }
    }

I have tried the following: 
CSS: 
.center-circle {
    -fx-fill: black;
}

.button {
    -fx-background-color: lightblue;
    -fx-border-color: blue;
    -fx-border-radius: 15px;
}

.pane {
    -fx-background-color: transparent;
}

#circularMenuPane {
    visibility: hidden;
    opacity: 0;
}

#circularMenuPane.visible {
    visibility: visible;
    opacity: 1;
 private void hideMenu() {
        // Check and remove the circularMenuPane from its parent
        Node parent = circularMenuPane.getParent();
        if (parent != null) {
            System.out.println("Removing circularMenuPane from parent: " + ((Pane) parent).getId());
            ((Pane) parent).getChildren().remove(circularMenuPane);
            circularMenuPane.setVisible(false);
            circularMenuPane.setManaged(false);
            circularMenuPane.getChildren().clear();
            System.out.println("Menu hidden and pane removed from parent");
            // Force a refresh of the parent container
            ((Pane) parent).layout();
        } else {
            System.out.println("circularMenuPane has no parent");
        }
        popup.hide();
    }

private void hideMenu() {
    if (popup != null) {
        popup.hide();
    }
    
    // Debugging output to trace parent and children
    Pane parent = (Pane) circularMenuPane.getParent();
    if (parent != null) {
        System.out.println("Removing circularMenuPane from parent: " + parent.getId());
        System.out.println("Parent before removal: " + parent.getChildren());
        parent.getChildren().remove(circularMenuPane);
        System.out.println("Parent after removal: " + parent.getChildren());
    } else {
        System.out.println("circularMenuPane parent is null, cannot remove.");
    }

    circularMenuPane.getChildren().clear();
    circularMenuPane.setVisible(false);
    circularMenuPane.setManaged(false);

    // Ensure the UI is updated
    circularMenuPane.getScene().getWindow().sizeToScene();
    System.out.println("Menu hidden and pane removed from parent");
}`
```

New contributor

Rodney Bowden is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật