@@ -249,6 +249,16 @@ static Icon magnifier() {
249249 return new MagnifierIcon ();
250250 }
251251
252+ /**
253+ * Foreground color with which to paint an icon. Note: The component may be
254+ * null, e.g. when macOS renders icons for its native screen menu bar.
255+ */
256+ private static Color foreground (final Component c ) {
257+ if (c != null ) return c .getForeground ();
258+ final Color color = UIManager .getColor ("MenuItem.foreground" );
259+ return color != null ? color : Color .GRAY ;
260+ }
261+
252262 /**
253263 * Icon painted from SVG path data (absolute M, L, C and Z commands)
254264 */
@@ -279,7 +289,7 @@ private static class GlyphIcon extends FlatAbstractIcon {
279289
280290 @ Override
281291 protected void paintIcon (final Component c , final Graphics2D g ) {
282- Color color = light == null ? c . getForeground ( ) : FlatLaf .isLafDark () ? dark : light ;
292+ Color color = light == null ? foreground ( c ) : FlatLaf .isLafDark () ? dark : light ;
283293 if (disabled ) {
284294 final Color d = UIManager .getColor ("Button.disabledText" );
285295 color = (d != null ) ? d : Color .GRAY ;
@@ -345,7 +355,7 @@ private abstract static class WindowIcon extends FlatAbstractIcon {
345355
346356 @ Override
347357 protected void paintIcon (final Component c , final Graphics2D g ) {
348- g .setColor (c . getForeground ( ));
358+ g .setColor (foreground ( c ));
349359 g .drawRoundRect (1 , 2 , 13 , 11 , 3 , 3 );
350360 paintContent (g , c instanceof AbstractButton && ((AbstractButton ) c ).isSelected ());
351361 }
@@ -374,7 +384,7 @@ public void paintIcon(final Component c, final Graphics g, final int x, final in
374384 final Graphics2D g2 = (Graphics2D ) g .create ();
375385 try {
376386 FlatUIUtils .setRenderingHints (g2 );
377- g2 .setColor (c . getForeground ( ));
387+ g2 .setColor (foreground ( c ));
378388 g2 .setStroke (new BasicStroke (UIScale .scale (1.3f ), BasicStroke .CAP_ROUND , BasicStroke .JOIN_ROUND ));
379389 final float s = getIconWidth ();
380390 final float a = s * .3f ; // inset
@@ -402,7 +412,7 @@ public void paintIcon(final Component c, final Graphics g, final int x, final in
402412 final Graphics2D g2 = (Graphics2D ) g .create ();
403413 try {
404414 FlatUIUtils .setRenderingHints (g2 );
405- g2 .setColor (c . getForeground ( ));
415+ g2 .setColor (foreground ( c ));
406416 g2 .setStroke (new BasicStroke (UIScale .scale (1.6f ), BasicStroke .CAP_ROUND , BasicStroke .JOIN_ROUND ));
407417 final float s = getIconWidth ();
408418 FlatUIUtils .drawShapePure (g2 , new Ellipse2D .Float (x + .1f * s , y + .1f * s , .6f * s , .6f * s ));
0 commit comments