[JAVA] Use the Mac menu bar with Processing 3 apps

The menu bar at the top of your Mac desktop Let's use it in an application created with Processing3.

menubar.png

Caution

--Operating environment: processing3.3 --The menu bar at the top of the desktop can only be used after exporting as an app

Contents

To create a menu bar, use JMenuBar in Java's Swing.

sample.pde


import java.awt.*;
import javax.swing.*;

JLayeredPane pane = new JLayeredPane();
JMenuBar  menubar = new JMenuBar();

void setup() {
  System.setProperty("apple.laf.useScreenMenuBar", "true");
  
  Canvas canvas = (Canvas) surface.getNative();
  pane = (JLayeredPane) canvas.getParent().getParent();

  JMenu     menu = new JMenu("menu");
  JMenuItem item = new JMenuItem("item");
  menu.add(item);
  menubar.add(menu);
  pane.add(menubar);
}

System.setProperty("apple.laf.useScreenMenuBar", "true"); This will allow you to use the Mac menu bar.

If it looks like this, it's a success.

スクリーンショット 2017-06-18 22.40.12.png

reference

Use AWT / swing in processing3.

Recommended Posts

Use the Mac menu bar with Processing 3 apps
Image processing: Let's play with the image
[Swing] How to display an arbitrary name on the menu bar on Mac
[Processing × Java] How to use the loop
[Processing × Java] How to use the class
Check the processing contents with [rails] binding.pry
Play with the Processing libraries "ControlP5", "Fisica"
Implement the box ball system with Processing
[Processing × Java] How to use the function
Use JDBC Manager with the settings in jdbc.dicon.
The story of tuning android apps with libGDX
How to use nginx-ingress-controller with Docker for Mac
Christmas with Processing
Control the processing flow of Spring Batch with JavaConfig.