RFR: 8346753: Test javax/swing/JMenuItem/RightLeftOrientation/RightLeftOrientation.java fails on Windows Server 2025 x64 because the icons of RBMenuItem and CBMenuItem are not visible in Nimbus LookAndFeel

Alexey Ivanov aivanov at openjdk.org
Tue Jun 24 17:26:27 UTC 2025


On Tue, 24 Jun 2025 16:14:28 GMT, Prasanta Sadhukhan <psadhukhan at openjdk.org> wrote:

> I dont think the test is invalid..It was in closed repo and tested for so many years before it got opensourced L&F is anyway applied to entire component tree in the fix via `SwingUtilities.updateComponentTreeUI(frame);`

I believe what fixed the test is that you removed the line `UIManager.setLookAndFeel(save)` which restored the L&F to whatever L&F that was set before at the time when the test started, in this particular case Nimbus L&F according to the bug description.

This ensures the current L&F remains Windows L&F so that the missing resources are now found. If there were another L&F to test, or if Windows L&F weren't the last in the list, the test will continue to fail because the current L&F will again be different from Windows L&F.

Indeed, it does. If I comment out `UIManager.setLookAndFeel(save)` from the original test code, the menu items under Windows do have check marks and bullets.

At the same time, `SwingUtilities.updateComponentTreeUI(frame)` has no effect… however, it does change the L&F of the menu bar and the menu items on the menu bar.

The menu items that are displayed in popups aren't visible and aren't part of the component hierarchy, therefore they remain at the assigned L&F which was active when they were created.

> Similar method was used in opensourced test javax/swing/JTabbedPane/bug4499556.java by @prrace ..Its the similar strategy used in many closed/open manual tests for testing different L&Fs in applet era

Yes, I've seen other tests which employ this strategy… where several components in a container are created with different L&Fs. And often everything seem to work… except for the cases where it doesn't.

This is the case where it doesn't…

Continuing with my example above where I commented out the line `UIManager.setLookAndFeel(save)`, the **Windows** menu looks good but clicking the **Metal** menu now throws NPE:


java.lang.NullPointerException: Cannot invoke "java.awt.Font.hashCode()" because "font" is null
	at java.desktop/sun.font.FontDesignMetrics$MetricsKey.init(FontDesignMetrics.java:213)
	at java.desktop/sun.font.FontDesignMetrics.getMetrics(FontDesignMetrics.java:282)
	at java.desktop/sun.swing.SwingUtilities2.getFontMetrics(SwingUtilities2.java:1235)
	at java.desktop/javax.swing.JComponent.getFontMetrics(JComponent.java:1700)
	at java.desktop/sun.swing.MenuItemLayoutHelper.reset(MenuItemLayoutHelper.java:126)
	at java.desktop/javax.swing.plaf.synth.SynthMenuItemLayoutHelper.<init>(SynthMenuItemLayoutHelper.java:118)
	at java.desktop/javax.swing.plaf.synth.SynthGraphicsUtils.paint(SynthGraphicsUtils.java:578)
	at java.desktop/javax.swing.plaf.synth.SynthMenuUI.paint(SynthMenuUI.java:278)
	at java.desktop/javax.swing.plaf.synth.SynthMenuUI.update(SynthMenuUI.java:245)
	at java.desktop/javax.swing.JComponent.paintComponent(JComponent.java:852)
	at java.desktop/javax.swing.JComponent.paint(JComponent.java:1128)
	at java.desktop/javax.swing.JComponent.paintChildren(JComponent.java:961)
	at java.desktop/javax.swing.JComponent.paint(JComponent.java:1137)
	at java.desktop/javax.swing.JComponent.paintToOffscreen(JComponent.java:5324)


This makes sense, the **Metal** menu itself was created while Nimbus was the active L&F. (Yes, you moved the menu creation after the new L&F was set.) This just proves my point that multiple L&Fs aren't really supported.

> @prrace Any comments on this test regarding its validity and fix?

I'm looking forward to seeing Phil's comments.

-------------

PR Comment: https://git.openjdk.org/jdk/pull/25907#issuecomment-3001288429


More information about the client-libs-dev mailing list