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

[macos]: Swing app packaged with jpackage does not show Menu Bar

    XMLWordPrintable

    Details

    • Subcomponent:
    • CPU:
      x86_64
    • OS:
      os_x

      Description

      ADDITIONAL SYSTEM INFORMATION :
      macOs Swing app packaged with jpackage does not show Menu Bar if apple.laf.useScreenMenuBar=true.
      This problem does not occur when running the app before packaging.
      Problem persists if property -Dapple.laf.useScreenMenuBar=true is asked to be passed at startup.

      A DESCRIPTION OF THE PROBLEM :
      macOs Swing app packaged with jpackage does not show Menu Bar if apple.laf.useScreenMenuBar=true


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Create a jpackage on macOS and OpenJDK 16 with the provided source code in this form.

      Example:
      jpackage --input /Users/nicolasdepomereu/Desktop/MenuTest --main-jar /Users/nicolasdepomereu/Desktop/MenuTest/menutest-1.0.jar

      (Jar created with Netbeans)

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The "File" menu should display when running the app packaged with jpackage.
      ACTUAL -
      The "File" menu does not show when running the app packaged with jpackage.

      ---------- BEGIN SOURCE ----------
      package menutest;

      import javax.swing.GroupLayout;
      import javax.swing.JMenu;
      import javax.swing.JMenuBar;
      import javax.swing.JMenuItem;

      public class MenuTestFrame extends javax.swing.JFrame {

          public MenuTestFrame() {
              setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
                      
              JMenuBar jMenuBar1 = new JMenuBar();
              JMenu jMenu1 = new JMenu();
              JMenuItem jMenuItem1 = new JMenuItem();

              jMenu1.setText("File");
              jMenuItem1.setText("New File");
              jMenu1.add(jMenuItem1);
              jMenuBar1.add(jMenu1);
              setJMenuBar(jMenuBar1);

              GroupLayout layout = new GroupLayout(getContentPane());
              getContentPane().setLayout(layout);
              layout.setHorizontalGroup(
                  layout.createParallelGroup(GroupLayout.Alignment.LEADING)
                  .addGap(0, 400, Short.MAX_VALUE)
              );
              layout.setVerticalGroup(
                  layout.createParallelGroup(GroupLayout.Alignment.LEADING)
                  .addGap(0, 274, Short.MAX_VALUE)
              );

              pack();
          }
         
          public static void main(String args[]) {
              
             System.setProperty("apple.laf.useScreenMenuBar", "true");
                   
              java.awt.EventQueue.invokeLater(new Runnable() {
                  public void run() {
                      new MenuTestFrame().setVisible(true);
                  }
              });
          }
      }

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

      FREQUENCY : always


        Attachments

          Activity

            People

            Assignee:
            almatvee Alexander Matveev
            Reporter:
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: