Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8188085

No more screen menu bar in .app bundles under macOS High Sierra 10.13 with apple.laf.useScreenMenuBar set to true

    XMLWordPrintable

Details

    Description

      FULL PRODUCT VERSION :
      java version "1.8.0_144"
      Java(TM) SE Runtime Environment (build 1.8.0_144-b01)
      Java HotSpot(TM) 64-Bit Server VM (build 25.144-b01, mixed mode)


      ADDITIONAL OS VERSION INFORMATION :
      Darwin 17.0.0 Darwin Kernel Version 17.0.0: Thu Aug 24 22:01:05 PDT 2017; root:xnu-4570.1.46~3/RELEASE_X86_64 x86_64
      macOS High Sierra 10.13 GM build 17A362a

      A DESCRIPTION OF THE PROBLEM :
      When the System property "apple.laf.useScreenMenuBar" is set to "true", the JMenuBar instance set on the displayed frame should appear in the macOS screen menu bar. This is not the case under macOS High Sierra 10.13 GM anymore when the application is run from an .app bundle.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      In a temporary folder, create a JMenuBarTest.java file containing the source code provided in this report.

      Under macOS, install JDK 8u144, open a Terminal Window, change directory to the folder where JMenuBarTest.java is stored and run the 3 following commands to generate a JMenuBarTest.app bundled application:

      javac JMenuBarTest.java

      /Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home/bin/javapackager -createjar -appclass JMenuBarTest -srcdir . -outdir . -outfile JMenuBarTest.jar

      /Library/Java/JavaVirtualMachines/jdk1.8.0_144.jdk/Contents/Home/bin/javapackager -deploy -outdir . -outfile JMenuBarTest -srcdir . -srcfiles JMenuBarTest.jar -appclass JMenuBarTest -name "JMenuBarTest" -native image


      Double-click on the JMenuBarTest.app test program under macOS 10.13.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      I expected that the "File" menu with its item "Hello" would appear beside "JMenuBarTest" menu in macOS screen menu bar.
      ACTUAL -
      The macOS screen menu bar displays only an empty "JMenuBarTest" menu.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.awt.event.ActionEvent;
      import javax.swing.*;

      public class JMenuBarTest {
        public static void main(String [] args) {
          System.setProperty("apple.laf.useScreenMenuBar", "true");
          
          final JFrame frame = new JFrame();
          JMenuItem menuItem = new JMenuItem(new AbstractAction("Hello") {
              public void actionPerformed(ActionEvent ev) {
                JOptionPane.showMessageDialog(frame, "Hello");
              }
            });

          JMenuBar menuBar = new JMenuBar();
          frame.setJMenuBar(menuBar);
          JMenu fileMenu = new JMenu("File");
          menuBar.add(fileMenu);
          fileMenu.add(menuItem);
          frame.setVisible(true);
        }
      }

      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Two worakarounds:
      - Run the application from its Jar executable file, but macOS users are not used to run applications with a Jar executable file, and this requires to install a JRE. This kind of executable file isn't accepted in the Mac App Store too.
      - Do not set the "apple.laf.useScreenMenuBar" System property to "true", or set it to "false" to keep the menu bar at the top of the frame, but macOS users don't expect this experience from applications under macOS.

      Replacing JMenuBar, JMenu and JMenuItem classes by MenuBar, Menu and MenuItem classes didn't work better.

      Attachments

        1. JMenuBarTest.java
          0.7 kB
        2. AppResult-8u144.PNG
          AppResult-8u144.PNG
          89 kB
        3. menubar_bug.mov
          12.44 MB

        Activity

          People

            serb Sergey Bylokhov
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: