ScaledImageIcon: do not throw exceptions if image has invalid size (e.g. not found); instead paint a red rectangle (similar to FlatSVGIcon)

This commit is contained in:
Karl Tauber
2022-10-01 20:12:32 +02:00
parent e83c26a76a
commit 1a456d5d68
2 changed files with 10 additions and 0 deletions

View File

@@ -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

View File

@@ -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"