5

Bug Report

This has been confirmed as a bug. You can track it here:

https://bugs-stage.openjdk.java.net/browse/JDK-8258934

Background

  • There's no other code running besides what I've posted in the MCVE; there are no other JVMs active when running this program (though I don't believe that should matter).

  • I do not have any programs installed which customizes the UI of my system.

Target Environment

Java 1.8.0_201
Windows 10 Home Edition

Tested JDKs

  • JDK 8 to JDK 15

Tested by third party

  • George Z. - Windows 7 - Can reproduce bug
  • David Kroukamp - Windows 10, JDK 10 - Can reproduce bug
  • camickr - Windows 10, JDK 11 - Can reproduce bug
  • Canvas (Discord) - Windows 10 - Can reproduce bug
  • Pawnee (Discord) - macOS Catalina 10.15.7, JDK 15 - Unable to reproduce bug

MCVE

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);
    }
}

Reproduction Steps

  1. Run the MCVE
  2. Click through the menus
  3. Resize the window
  4. Click through the menus again

MCVE Results

Windows 10 machine targeting JDK 11 (though similar results on all tested major Java distributions):

enter image description here

  • Menus give different render results before & after resizing the window
  • There's overlap of the highlighting - the highlight of "New..." bleeds into the "Report" menu item.

  • Sometimes the arrow of "New..." will get overlapped by "Report" as shown below.

Windows 7 - image by George Z

enter image description here

Windows 10, JDK - image by Canvas (Discord)

enter image description here


New Findings

The highlight bug does not appear if part of the "Report" menu item is outside of the windows bounds.

enter image description here

This was achieved by updating the popout offset for menus:

// apply this before creating any components
UIManager.put("Menu.menuPopupOffsetX", 20);
UIManager.put("Menu.menuPopupOffsetY", 20);

Works on...

  • macOS Catalina 10.15.7 - image by Pawnee (Discord)

enter image description here


Question

Does JMenu work properly with System L&F, and if so, what am I missing to get proper results? (No extra spacing, no highlights bleeding into other components)

Vince
  • 14,470
  • 7
  • 39
  • 84
  • 1
    [Same thing happens in Windows 7 as well](https://i.stack.imgur.com/Wzaf1.png) – George Z. Dec 21 '20 at 04:56
  • 1
    Works OK for me on Windows 10 using JDK 11. – camickr Dec 21 '20 at 05:27
  • 1
    Same as OP and I have window 10, jdk1.8.0_261. – David Kroukamp Dec 21 '20 at 06:15
  • 1
    I see the same results as you with your updated code. I don't see any problem with your code. I also downloaded the `MenuLookDemo` code from the Swing tutorial on [How to Use Menus](https://docs.oracle.com/javase/tutorial/uiswing/components/menu.html), changed the code to use System LAF and get the same results. so I would suggest this is a LAF bug. – camickr Dec 21 '20 at 17:13
  • @GeorgeZ.What version of Java are you using? – Vince Dec 21 '20 at 22:47

0 Answers0