NSMenuFX

NSMenuFX is a simple library allowing to access and modify the menu items that are generated by default for OS X applications

Лицензия

Лицензия

Группа

Группа

de.jangassen
Идентификатор

Идентификатор

nsmenufx
Последняя версия

Последняя версия

3.1.0
Дата

Дата

Тип

Тип

bundle
Описание

Описание

NSMenuFX
NSMenuFX is a simple library allowing to access and modify the menu items that are generated by default for OS X applications
Ссылка на сайт

Ссылка на сайт

https://github.com/0x4a616e/NSMenuFX
Система контроля версий

Система контроля версий

https://github.com/0x4a616e/NSMenuFX

Скачать nsmenufx

Зависимости

compile (3)

Идентификатор библиотеки Тип Версия
de.jangassen : jfa jar 1.2.0
org.openjfx : javafx-controls jar 11
org.openjfx : javafx-fxml jar 11

test (2)

Идентификатор библиотеки Тип Версия
org.junit.jupiter : junit-jupiter-engine jar 5.7.0
org.junit.jupiter : junit-jupiter-api jar 5.7.0

Модули Проекта

Данный проект не имеет модулей.

NSMenuFX

Codacy Badge Maven Central Test CodeQL Known Vulnerabilities

A simple library to customize the macOS menu bar to give your JavaFX app a more native look and feel.

NSMenuFX provides a mapping layer between the JavaFX Menu and AppKits NSMenu objects. It uses JNA to directly set the menus for your application using macOS native API.

Features

Here are a few examples of what you can do with NSMenuFX.

Application menu

Custom App Menu Screenshot

Customize the auto-generated application menu of your JavaFX app.

// Create the default Application menu
Menu defaultApplicationMenu = tk.createDefaultApplicationMenu("test");

// Update the existing Application menu
MenuToolkit.toolkit().setApplicationMenu(defaultApplicationMenu);

Window menu

Custom App Menu Screenshot

Create common macOS menus like the Window menu.

// Create the window menu
Menu windowMenu = new Menu("Window");
// ...
// Add your own menu items

// Automatically add windows
MenuToolkit.toolkit().autoAddWindowMenuItems(windowMenu);

Dock menu

Custom App Menu Screenshot

Create a dock icon menu. Note that images for menu items in dock menus are not supported by macOS.

// Create the dock menu
Menu menu = new Menu("Window");
// ...
// Add your own menu items

// Set the dock menu
MenuToolkit.toolkit().setDocIconMenu(menu);

Tray menu

Custom App Menu Screenshot

Add a tray menu. Pass null to remove the tray menu again.

// Create the tray menu
Menu menu = new Menu("Window");
// ...
// Add your own menu items

// Set the try menu
MenuToolkit.toolkit().setTrayMenu(menu);

Context menu

Custom App Menu Screenshot Custom App Menu Screenshot

Use the native context menu instead of a JavaFX based context menu.

// Create the context menu
Menu menu = new Menu();
// ...
// Add your own menu items

// Show the context menu when right-clicking the stage
scene.setOnMouseClicked(event ->
{
  if (event.getButton() == MouseButton.SECONDARY) {
    MenuToolkit.toolkit().showContextMenu(context, event);
  }
});

To adapt the context menu appearence, you can switch between LIGHT and DARK mode, or use AUTO to adapt the appearence of macOS.

// Set appearance automatically (or manually to DARK/LIGHT)
MenuToolkit.toolkit().setAppearanceMode(AppearanceMode.AUTO);

And more

  • Quickly create an "About" menu
  • Automatically use the same menu bar for all stages

To find more examples, check out the sample applications here.

Maven

Add the following lines to the dependencies in your pom.xml

<dependency>
    <groupId>de.jangassen</groupId>
    <artifactId>nsmenufx</artifactId>
    <version>3.1.0</version>
</dependency>

Gradle

Add the following line to the dependencies in your build.gradle

compile "de.jangassen:nsmenufx:3.1.0"

Migrating from 2.1

For most parts, the API has not changed. The most prominent difference is that the package name has changed from de.codecentric.centerdevice to de.jangassen to match the new maven coordinates. Also, the About dialog no longer uses a WebView, so it can either display plain text or a list of Text objects. If you want to continue using a WebView, you have to create one and pass that to the AboutStageBuilder:

WebView webView = new WebView();
webView.getEngine().loadContet("<b>Credits</b>");

AboutStageBuilder.start("My App").withNode(webView).build();

Known issues

NSMenuFX no longer supports changing the title of the application menu at runtime. This has always been a bit "hacky" as it is not really supported by macOS. As a result, the new name was no longer bold faced when it was changed with previous versions of NSMenuFX.

To set the title of the application menu to the name of your application, you need to bundle the application and set CFBundleName in Info.plist.

Версии библиотеки

Версия
3.1.0
3.0.2
3.0.1
3.0.0
3.0.0-BETA2
3.0.0-BETA1
2.1.8
2.1.7