Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create java applications with MacBook Pro touchbar support?

as the tile describe, I would love to have the ability to add some cool touchbar buttons to my java application for MacBook Pro 2016 users.. I've not seen yet if there is a way to implement it in java yet.

Anyone got some knowledge on that?

like image 668
Christian Moen Avatar asked Dec 18 '16 14:12

Christian Moen


People also ask

What can you do with Touchbar Macbook Pro?

If your Mac has a Touch Bar, you can use familiar gestures — like tap, swipe or slide — directly on the Touch Bar to adjust settings, use Siri, access function keys, and do tasks in different apps.

Can Java applications run on Mac?

Compiling and running a Java application on Mac OSX, or any major operating system, is very easy. Apple includes a fully-functional Java runtime and development environment out-of-the-box with OSX, so all you have to do is write a Java program and use the built-in tools to compile and run it.

How do I add apps to my Macbook Pro Touch Bar?

To always show function keys (F1, F2, and so on) in the Touch Bar for specific apps, choose Apple menu > System Preferences, click Keyboard, click Shortcuts, select Function Keys in the list on the left, then add the apps on the right.

Can you customize the touch bar on Macbook Pro?

In the Finder and in apps such as Mail and Safari, you can customize the buttons in the Touch Bar. You can also customize the Control Strip. Choose View > Customize Touch Bar to add, delete, or rearrange items in the Touch Bar.

How do I enable the Touch Bar on a MacBook Pro?

In the Settings/Preferences dialog ( Ctrl+Alt+S ), go to Appearance & Behavior | Menus and Toolbars. Expand the Touch Bar node and configure the controls for corresponding contexts and modifier keys. The Touch Bar node is available only if you are using an Apple MacBook Pro with the Touch Bar. Apply changes when finished.

Which MacBooks have a Touch Bar?

To take the tool to a fun new level, consider one of the many third-party Touch Bar apps on the market. The Touch Bar is available on the 13-inch MacBook Pro (2020) and earlier models, plus the 16-inch MacBook Pro (2019). Here are the best apps with Touch Bar support.

What apps are compatible with the Touch Bar?

Here are the best apps with Touch Bar support so far! Pixelmator Pro. BetterTouchTool. Evernote. Adobe Photoshop. djay Pro. Final Cut Pro X. Microsoft Office.

Is Apple’s Touch Bar still relevant?

It’s been almost three years since Apple introduced the Touch Bar to the world, and it’s still searching for a purpose. While it’s not any worse than the Function keys it replaced, Apple has really struggled to help it reach its potential and make it a truly excellent part of owning a MacBook Pro. This got us thinking.


2 Answers

There is a new Java library for interacting with the NSTouchBar API called JTouchBar.

For example using 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);

You can find the library on Github: https://github.com/Thizzer/JTouchBar

like image 120
Thizzer Avatar answered Oct 24 '22 10:10

Thizzer


By the looks of it, apple doesn't provide support for adding items to the touch bar, never mind doing it in java.

While going through some documentation for the touch bar, it would appear that you will also need an instance of the NSTouchBarItem class. Java doesn't have that, nor provide a way to get that. I doubt that using native methods would work as well, seeing how the instance is app specific and is passed to the application through apple.

Accessing the bar is possible, but only natively.

like image 3
Luke Melaia Avatar answered Oct 24 '22 09:10

Luke Melaia