@@ -154,6 +154,7 @@ class Icons {
154154 private final String path
155155 private final Closure<Color > colorMapper
156156 private FlatSVGIcon delegate
157+ private Icon disabledDelegate
157158 private int size
158159
159160 DynamicSVGIcon (String path , int size , Closure<Color > colorMapper ) {
@@ -164,20 +165,33 @@ class Icons {
164165
165166 void setSize (int newSize ) {
166167 this . size = newSize
167- this . delegate = new FlatSVGIcon (path, newSize, newSize)
168- refreshColors()
168+ rebuildDelegates()
169169 }
170170
171171 void refreshColors () {
172172 // rebuild the FlatSVGIcon entirely — setColorFilter alone leaves the
173173 // internal raster cache in a state where some contexts (notably the
174174 // macOS screen menu bar) keep painting blank icons after a theme switch
175+ rebuildDelegates()
176+ }
177+
178+ private void rebuildDelegates () {
175179 this . delegate = new FlatSVGIcon (path, size, size)
176180 delegate. setColorFilter(new FlatSVGIcon.ColorFilter (colorMapper as Function<Color , Color > ))
181+ // FlatSVGIcon.getDisabledIcon() returns a grayscale variant; we
182+ // dispatch to it in paintIcon when the target component is disabled,
183+ // since Swing/FlatLaf can't derive one from a generic Icon wrapper
184+ this . disabledDelegate = delegate. getDisabledIcon()
177185 }
178186
179187 @Override int getIconWidth () { size }
180188 @Override int getIconHeight () { size }
181- @Override void paintIcon (Component c , Graphics g , int x , int y ) { delegate. paintIcon(c, g, x, y) }
189+ @Override void paintIcon (Component c , Graphics g , int x , int y ) {
190+ if (c != null && ! c. isEnabled()) {
191+ disabledDelegate. paintIcon(c, g, x, y)
192+ } else {
193+ delegate. paintIcon(c, g, x, y)
194+ }
195+ }
182196 }
183197}
0 commit comments