Reputation: 15146
This has been confirmed as a bug. You can track it here:
https://bugs.openjdk.org/browse/JDK-8258934
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
Tested by third party
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);
}
}
Windows 10 machine targeting JDK 11 (though similar results on all tested major Java distributions):
Windows 7 - image by George Z
Windows 10, JDK - image by Canvas (Discord)
The highlight bug does not appear if part of the "Report" menu item is outside of the windows bounds.
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);
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)
Upvotes: 5
Views: 221