正如平铺所描述的,我希望能够向MacBook Pro 2016用户的Java应用程序中添加一些很酷的触摸栏按钮。

有人对此有所了解吗?

最佳答案

有一个新的Java库,用于与NSTouchBar API交互,称为JTouchBar

例如使用SWT

Shell shell = ...

JTouchBar jTouchBar = new JTouchBar();
jTouchBar.setCustomizationIdentifier("MySWTJavaTouchBar");

// flexible space
jTouchBar.addItem(new TouchBarItem(TouchBarItem.NSTouchBarItemIdentifierFlexibleSpace));

// button
TouchBarButton touchBarButtonImg = new TouchBarButton();
touchBarButtonImg.setTitle("Button 1");
touchBarButtonImg.setAction(new TouchBarViewAction() {
    @Override
    public void onCall( TouchBarView view ) {
        System.out.println("Clicked Button_1.");
    }
});

Image image = new Image();
img.setName(ImageName.NSImageNameTouchBarColorPickerFill);
touchBarButtonImg.setImage(image);

jTouchBar.addItem(new TouchBarItem("Button_1", touchBarButtonImg, true));

// label
TouchBarTextField touchBarTextField = new TouchBarTextField();
touchBarTextField.setStringValue("TextField 1");

jTouchBar.addItem(new TouchBarItem("TextField_1", touchBarTextField, true));

// enable touchbar
jTouchBar.enableForShell(shell);

您可以在Github上找到该库:
https://github.com/Thizzer/JTouchBar

10-07 13:26