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
Fri Jul 4 09:57:40 UTC 2025
On Fri, 4 Jul 2025 08:20:27 GMT, Abhishek Kumar <abhiscxk at openjdk.org> wrote:
>> Issue is RadioButtonMenuItem and CheckBoxMenuItem bullet/checkmark icon is not displayed in WindowsL&F when the test is run with NimbusL&F.
>> This is because `WindowsIconFactory#VistaMenuItemCheckIcon.paintIcon` called `getLaFIcon()` which returns a empty NimbusIcon which causes no icons to be drawn. This is because the test after setting WIndows L&F of the menuitem reverts back the Windows L&F to Nimbus L&F via `UIManager.setLookAndFeel(save);` call in the test so when frame is made visible, the L&F resets back to Nimbus L&F resulting in null NimbusIcon.
>>
>> Fix is made to make sure the whole frame is updated to cater to L&F change via `SwingUtilities.updateComponentTreeUI(frame);` call and keep the L&F without reverting back to original L&F..
>
> test/jdk/javax/swing/JMenuItem/RightLeftOrientation.java line 92:
>
>> 90: JMenuBar menuBar = new JMenuBar();
>> 91:
>> 92: menuBar.add(createMenu("javax.swing.plaf.metal.MetalLookAndFeel",
>
> I tried to extend the test (with this PR changes included) for all installed L&Fs and then create the menu for each L&F.
>
> UIManager.LookAndFeelInfo[] lafs = UIManager.getInstalledLookAndFeels();
> for (final UIManager.LookAndFeelInfo lafInfo : lafs) {
> System.out.println("installed laf className : " + lafInfo.getClassName());
> System.out.println("installed laf Name : " + lafInfo.getName());
> menuBar.add(createMenu(lafInfo.getClassName(), lafInfo.getName()));
> }
>
> Then the test failed with this exception
>
> 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)
>
> Otherwise the RBMI and CBMI does contain the icon after the fix.
This is similar to the exception that I got [above](https://github.com/openjdk/jdk/pull/25907#issuecomment-3001288429). It's just a result of mixing several L&Fs at the same time.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/25907#discussion_r2184908197
More information about the client-libs-dev
mailing list