diff --git a/CHANGELOG.md b/CHANGELOG.md index 19facdba..d296b7f6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,8 @@ FlatLaf Change Log button. - Arrow buttons in ComboBox, Spinner, ScrollBar and TabbedPane: Show "pressed" feedback only for left mouse button. +- ScaledImageIcon: Do not throw exceptions if image was has invalid size (e.g. + not found). Instead, paint a red rectangle (similar to `FlatSVGIcon`). ## 2.5 diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/util/ScaledImageIcon.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/util/ScaledImageIcon.java index 0d683ac9..e510382d 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/util/ScaledImageIcon.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/util/ScaledImageIcon.java @@ -16,6 +16,7 @@ package com.formdev.flatlaf.util; +import java.awt.Color; import java.awt.Component; import java.awt.Graphics; import java.awt.Graphics2D; @@ -102,6 +103,13 @@ debug*/ int imageWidth = image.getWidth( null ); int imageHeight = image.getHeight( null ); + // paint red rectangle if image has invalid size (e.g. not found) + if( imageWidth < 0 || imageHeight < 0 ) { + g.setColor( Color.red ); + g.fillRect( x, y, getIconWidth(), getIconHeight() ); + return; + } + // scale image if necessary to destination size if( imageWidth != destImageWidth || imageHeight != destImageHeight ) { // determine scaling method; default is "quality"