Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding styling to the menu-item #87

Open
xRuBYN opened this issue Aug 2, 2024 · 2 comments
Open

Adding styling to the menu-item #87

xRuBYN opened this issue Aug 2, 2024 · 2 comments

Comments

@xRuBYN
Copy link

xRuBYN commented Aug 2, 2024

Something like this

Screenshot 2024-08-02 at 15 53 43
@dustinkredmond
Copy link
Owner

Don't believe that we can since the FXTrayIcon class basically augments the AWT TrayIcon without doing anything too fancy. I will look into the latest API for TrayIcon but if nothing has changed recently I'll probably close this issue with some comment along the lines of "unable to implement".

@octopusYan
Copy link

Translate from Chinese to English:

I think we can override the MouseEvent that pops up Popupmenu without adding Popupmenu to TrayIcon to display Alert or Dialog, and then hide the taskbar icon through stage.initStyle(StageStyle.UTILITY)

like this:

trayIcon.addMouseListener(new MouseAdapter() {

            @Override
            public void mouseReleased(MouseEvent e) {
                maybeShowPopup(e);
            }

            @Override
            public void mousePressed(MouseEvent e) {
                maybeShowPopup(e);
            }

            private void maybeShowPopup(MouseEvent e) {
                // popup menu trigger event
                if (e.isPopupTrigger()) {
                    Platform.runLater(() -> {
                        Alert alert = new Alert(Alert.AlertType.INFORMATION);
                        alert.setTitle("a fake popupmenu");
                        alert.setHeaderText(null);
                        alert.setContentText("add some menu item ...");

                        Stage stage = WindowsUtil.getStage(alert.getDialogPane());
                        stage.initStyle(StageStyle.UTILITY);
                        
                        stage.focusedProperty().addListener((observable, oldValue, newValue) -> {
                            System.out.println(STR."Stage focused is \{newValue}");
                            if (!newValue) {
                                alert.hide();
                            }
                        });

                        alert.show();
                    });
                }
            }
        });


I also feel that the style of awt's Popupmenu, which cannot be customized, is dull. I am planning to do so in my project

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants