mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2026-02-11 06:27:13 -06:00
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:
@@ -13,6 +13,8 @@ FlatLaf Change Log
|
|||||||
button.
|
button.
|
||||||
- Arrow buttons in ComboBox, Spinner, ScrollBar and TabbedPane: Show "pressed"
|
- Arrow buttons in ComboBox, Spinner, ScrollBar and TabbedPane: Show "pressed"
|
||||||
feedback only for left mouse button.
|
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
|
## 2.5
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
|
|
||||||
package com.formdev.flatlaf.util;
|
package com.formdev.flatlaf.util;
|
||||||
|
|
||||||
|
import java.awt.Color;
|
||||||
import java.awt.Component;
|
import java.awt.Component;
|
||||||
import java.awt.Graphics;
|
import java.awt.Graphics;
|
||||||
import java.awt.Graphics2D;
|
import java.awt.Graphics2D;
|
||||||
@@ -102,6 +103,13 @@ debug*/
|
|||||||
int imageWidth = image.getWidth( null );
|
int imageWidth = image.getWidth( null );
|
||||||
int imageHeight = image.getHeight( 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
|
// scale image if necessary to destination size
|
||||||
if( imageWidth != destImageWidth || imageHeight != destImageHeight ) {
|
if( imageWidth != destImageWidth || imageHeight != destImageHeight ) {
|
||||||
// determine scaling method; default is "quality"
|
// determine scaling method; default is "quality"
|
||||||
|
|||||||
Reference in New Issue
Block a user