@@ -238,6 +238,16 @@ static Icon magnifier() {
238238 return new MagnifierIcon ();
239239 }
240240
241+ /**
242+ * Foreground color with which to paint an icon. Note: The component may be
243+ * null, e.g. when macOS renders icons for its native screen menu bar.
244+ */
245+ private static Color foreground (final Component c ) {
246+ if (c != null ) return c .getForeground ();
247+ final Color color = UIManager .getColor ("MenuItem.foreground" );
248+ return color != null ? color : Color .GRAY ;
249+ }
250+
241251 /**
242252 * Icon painted from SVG path data (absolute M, L, C and Z commands)
243253 */
@@ -268,7 +278,7 @@ private static class GlyphIcon extends FlatAbstractIcon {
268278
269279 @ Override
270280 protected void paintIcon (final Component c , final Graphics2D g ) {
271- Color color = light == null ? c . getForeground ( ) : FlatLaf .isLafDark () ? dark : light ;
281+ Color color = light == null ? foreground ( c ) : FlatLaf .isLafDark () ? dark : light ;
272282 if (disabled ) {
273283 final Color d = UIManager .getColor ("Button.disabledText" );
274284 color = (d != null ) ? d : Color .GRAY ;
@@ -334,7 +344,7 @@ private abstract static class WindowIcon extends FlatAbstractIcon {
334344
335345 @ Override
336346 protected void paintIcon (final Component c , final Graphics2D g ) {
337- g .setColor (c . getForeground ( ));
347+ g .setColor (foreground ( c ));
338348 g .drawRoundRect (1 , 2 , 13 , 11 , 3 , 3 );
339349 paintContent (g , c instanceof AbstractButton && ((AbstractButton ) c ).isSelected ());
340350 }
@@ -363,7 +373,7 @@ public void paintIcon(final Component c, final Graphics g, final int x, final in
363373 final Graphics2D g2 = (Graphics2D ) g .create ();
364374 try {
365375 FlatUIUtils .setRenderingHints (g2 );
366- g2 .setColor (c . getForeground ( ));
376+ g2 .setColor (foreground ( c ));
367377 g2 .setStroke (new BasicStroke (UIScale .scale (1.3f ), BasicStroke .CAP_ROUND , BasicStroke .JOIN_ROUND ));
368378 final float s = getIconWidth ();
369379 final float a = s * .3f ; // inset
@@ -391,7 +401,7 @@ public void paintIcon(final Component c, final Graphics g, final int x, final in
391401 final Graphics2D g2 = (Graphics2D ) g .create ();
392402 try {
393403 FlatUIUtils .setRenderingHints (g2 );
394- g2 .setColor (c . getForeground ( ));
404+ g2 .setColor (foreground ( c ));
395405 g2 .setStroke (new BasicStroke (UIScale .scale (1.6f ), BasicStroke .CAP_ROUND , BasicStroke .JOIN_ROUND ));
396406 final float s = getIconWidth ();
397407 FlatUIUtils .drawShapePure (g2 , new Ellipse2D .Float (x + .1f * s , y + .1f * s , .6f * s , .6f * s ));
0 commit comments