Access Mac OS X Application Menu with Java

I am writing a Java application designed for all platforms, but in particular I am working on the appearance and integration of OS X (I use NetBeans on my MacBook Pro). I would like to access the application menu, i.e. A bold menu named after the application. I want to register listeners for the About and Quit elements, and also show the Preferences element. I would not mind adding a few more of my own.

So how do I do this? I saw that the previous posts were related to the OSXAdapter, but the geniuses at Apple decided to remove it from their library (or rename it ambiguously), because all links were redirected to the main page, and all my searches were fruitless. I also saw the MacOSAppAdapter class, but I'm not sure how to use it. All importing and new classes and hierarchies are a little confused.

EDIT:

This is what I did to link the About, Preferences, and Quit elements:

I created a new class, MacOSXAboutHandler, which extends

com.apple.eawt.Application 

Its constructor just calls

 setAboutHandler(AboutHandler aH) 

and I provide it with my own listener, which expands

 AboutHandler 

In my main class, I determine if I'm running on a Mac using

 System.getProperty("os.name").contains("mac") 

If true, I'm just creating a new instance of MacOSXAboutHandler. The constructor adds my handler, and whenever the application is launched (or even tested in NetBeans), clicking on the About ... element in the selected application menu executes the code that I specified in my AboutHandler.

The same is done for preference and termination, simply replacing the occurrences of "about" with the appropriate action. All of these handlers are written like any other Java listener.

+4
source share
1 answer

You might want to take a look at Casting your Java application on Mac OS X and (more importantly) Casting your Java application on Mac OS X Part 2 and Casting your Java application on Mac OS X Part 3

You can use the Java System Properties Reference for Mac to use

You can take a look at the Apple Java Extensions API , from my brief reading, it seems you basically want to use the default instance if com.apple.eawt.Application and put the handlers you need (for example, setAboutHandler ).

You can also read Mac OS X About, Quit and Preferences Articles about events and events , which should provide some additional tips.

+2
source

Source: https://habr.com/ru/post/1203521/


All Articles