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

Visual bugs with JMenu when using System L&F

    Details

    • Subcomponent:
    • Introduced In Build:
      b01
    • Introduced In Version:
    • CPU:
      x86_64
    • OS:
      windows_10

      Description

      ADDITIONAL SYSTEM INFORMATION :
      Windows 10 Home
      JDK 15.0.1

      A DESCRIPTION OF THE PROBLEM :
      When using System L&F with extremely basic Swing programs (including the How to use Menus trail), JMenu gives inconsistent results on different machines.

      Seems to work fine on Mac, but have seen inconsistent results on Windows 10 and Windows 7; two people with Windows 10 may experience different results, although using the same OS.

      Tested with Java 8 to 15, occurs on all releases.

      Please refer to this Stack Overflow post: https://stackoverflow.com/questions/65387329/why-does-jmenu-not-render-correctly-when-using-system-lf

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run the program
      Use menu before resizing to see (some-what) proper results
      Resize the window

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Proper native graphics, consistent with other Windows applications (no highlight bleeding, no inconsistencies when resizing the window)
      ACTUAL -
      Highlight of "New..." bleeds into "Report" item, Z-Indexing of components seem to be ignored

      ---------- BEGIN SOURCE ----------
      import javax.swing.*;

      public class Demo {
          public static void main(String[] args) {
              SwingUtilities.invokeLater(Demo::launchUI);
          }

          private static void launchUI() {
              try {
                  UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
              } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException e) {
                  e.printStackTrace();
              }

              JFrame frame = new JFrame();
              JMenuItem report = new JMenuItem("Report");
              JMenu newMenu = new JMenu("New...");
              JMenu fileMenu = new JMenu("File");
              JMenuBar bar = new JMenuBar();

              newMenu.add(report);
              fileMenu.add(newMenu);
              bar.add(fileMenu);
              frame.setJMenuBar(bar);

              frame.pack();
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              frame.setVisible(true);
          }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      - Do not use System L&F (not much of a work-around; native feel is required)

      FREQUENCY : always


        Attachments

        1. Capture1.JPG
          Capture1.JPG
          51 kB
        2. Demo.java
          1.0 kB

          Activity

            People

            • Assignee:
              bvaidya Balchandra Vaidya
              Reporter:
              webbuggrp Webbug Group
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated: