> On Jan 16, 2023, at 10:33 PM, Scott Palmer <swpal...@gmail.com> wrote:
> 
> There are third-party libraries for better integration with the Mac menu bar.
> 
> E.g. https://github.com/codecentric/NSMenuFX 
> <https://github.com/codecentric/NSMenuFX>
> 
> Though I wish this wasn’t necessary and proper hooks were present in JavaFX 
> to begin with.
> 

That does look like it provides the About menu item. In looking at this I 
didn’t determine why JavaFX app’s don’t get the default ‘Cocoa’ one Swing app’s 
do (free of charge, no need for java.awt.Desktop or any app changes at all). 
This should just work. If the changes I provided in the bug report were used 
you would get this by simply including…

        static {
                //java.awt.Toolkit.getDefaultToolkit(); // Start AppKit
                Thread t = new Thread(() -> { 
java.awt.Toolkit.getDefaultToolkit(); });
        t.start();  
        }

The thread change seemed necessary to hit ApplicationDelegate with access to 
the menubar. I don’t know yet if it will be considered in the scope of the bug 
fix to determine why the code doesn’t work as-is and eliminate the need for 
this.

I think originally the setAboutHandler and other functionalities of 
java.awt.Desktop were the jdk’s attempt to get rid of the equivalent Apple 
API’s as a sort of 3rd party add on. I wondered if it might not be more 
generally useful for JavaFX to have full access to java.awt.Desktop. I did go 
so far as to verify that with the following…

public class HelloWorld extends Application implements AboutHandler {

        @Override
        public void init() {
        Thread t = new Thread(() -> {
                        Desktop desktop = Desktop.getDesktop();
                        desktop.setAboutHandler((AboutHandler)this);   
                });
                t.start();                                              
        }

    public void handleAbout(AboutEvent evt) {
        System.out.println("got to handleAbout");
        Platform.runLater(() -> {
                Alert alert = new Alert(AlertType.INFORMATION, "About 
HelloWorld");
                        alert.showAndWait();
                });
    }

Again, the thread changes seemed necessary. 
I don’t make much other use of java.awt.Desktop anywhere myself. But possibly 
other JavaFX developers would find some of it’s functionality useful or 
necessary. So I think long term some determination might need to made if JavaFX 
will develop all of this themselves. Or, use of java.awt.Desktop can continue 
to be used. Whether any attempt to address that will be made in resolving the 
bug report I don’t know. From the jdk side they could possibly figure out some 
way to provide this without some of the Thread changes. Or indicate if any 
support for java.awt.Desktop for JavaFX applications will be made at all.

Reply via email to