dustinkredmond / FXTrayIcon

Tray Icon implementation for JavaFX applications. Say goodbye to using AWT's SystemTray icon, instead use a JavaFX Tray Icon.
MIT License
327 stars 26 forks source link

Support CheckMenuItem as menu item #55

Closed azplanlos closed 2 years ago

azplanlos commented 2 years ago

This PR introduces support for CheckMenuItem as menu item as discussed in #51 - Might need JDK 9 to compile but not sure about this.

dustinkredmond commented 2 years ago

This is perfect, I will merge. Thank you for your contribution!

I will include a runnable test in the test directory for this type of menu item.

azplanlos commented 2 years ago

Hi Michael,

You are right, this might be a limitation of my implementation. As the JavaFX MenuItems aren‘t bound to their Swing version you can’t set the checked property afterwards. If you need this, let me have a look if it can be done.

Andreas


Von: Michael Sims @.> Gesendet: Tuesday, June 14, 2022 11:11:12 PM An: dustinkredmond/FXTrayIcon @.> Cc: Andreas Zöllner @.>; Mention @.> Betreff: Re: [dustinkredmond/FXTrayIcon] Support CheckMenuItem as menu item (PR #55)

@azplanloshttps://github.com/azplanlos - I created this class, but the onAction event doesn't work ... any thoughts?

import javafx.application.Application; import javafx.scene.control.CheckMenuItem; import javafx.stage.Stage;

public class CheckMenu extends Application {

    CheckMenuItem cmuApples = new CheckMenuItem("Apples");
    CheckMenuItem cmuOranges = new CheckMenuItem("Oranges");
    CheckMenuItem cmuPears = new CheckMenuItem("Pears");

    @Override
    public void start(Stage primaryStage) {
            primaryStage.setTitle("Default Icon");

            FXTrayIcon fxti = new FXTrayIcon.Builder(primaryStage)
                            .show()
                            .build();

            cmuApples.setOnAction(e->{
                    if(cmuApples.isSelected()) {
                            cmuOranges.setSelected(false);
                            cmuPears.setSelected(false);
                    }
            });

            cmuOranges.setOnAction(e->{
                    if(cmuApples.isSelected()) {
                            cmuApples.setSelected(false);
                            cmuPears.setSelected(false);
                    }
            });

            cmuPears.setOnAction(e->{
                    if(cmuApples.isSelected()) {
                            cmuApples.setSelected(false);
                            cmuOranges.setSelected(false);
                    }
            });

            fxti.addMenuItem(cmuApples);
            fxti.addMenuItem(cmuOranges);
            fxti.addMenuItem(cmuPears);

    }

    public static void main(String[] args) {
            launch(args);
    }

}

— Reply to this email directly, view it on GitHubhttps://github.com/dustinkredmond/FXTrayIcon/pull/55#issuecomment-1155716671, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AARE55T6DPVVRS3AIB3E2FLVPDYPBANCNFSM5YWXLK2A. You are receiving this because you were mentioned.Message ID: @.***>

EasyG0ing1 commented 2 years ago

@azplanlos - Already got it ... PR #56

It's not as clean as being able to use the original objects that are passed into FXTrayIcon, but such is the nature of the system tray under JavaFX ... it's really just "smoke and mirrors" ... but it does the job.

EasyG0ing1 commented 2 years ago

@azplanlos - nice job by the way on figuring it out. Nice and clean implementation too.