Merge PR #1080: Fix NPE in FlatUIDefaultsInspector when color is null

This commit is contained in:
Karl Tauber
2026-01-13 19:31:56 +01:00
2 changed files with 26 additions and 11 deletions

View File

@@ -8,6 +8,10 @@ FlatLaf Change Log
- Popup: Fixed scrolling popup painting issue on Windows 10 when a glass pane is - Popup: Fixed scrolling popup painting issue on Windows 10 when a glass pane is
visible and frame is maximized. (issue #1071) visible and frame is maximized. (issue #1071)
- ToolBar: Grip disappeared when switching between Look and Feels. (issue #1075) - ToolBar: Grip disappeared when switching between Look and Feels. (issue #1075)
- Extras:
- UI defaults inspector: Fixed NPE if color of `FlatLineBorder` is null. Also
use `FlatLineBorder` line color as cell background color in "Value" column.
(PR #1080)
## 3.7 ## 3.7

View File

@@ -777,6 +777,9 @@ public class FlatUIDefaultsInspector
@SuppressWarnings( "FormatString" ) // Error Prone @SuppressWarnings( "FormatString" ) // Error Prone
private static String color2hex( Color color ) { private static String color2hex( Color color ) {
if( color == null )
return "";
int rgb = color.getRGB(); int rgb = color.getRGB();
boolean hasAlpha = color.getAlpha() != 255; boolean hasAlpha = color.getAlpha() != 255;
@@ -1018,28 +1021,36 @@ public class FlatUIDefaultsInspector
item = (Item) value; item = (Item) value;
init( table, item.key, isSelected, row ); init( table, item.key, isSelected, row );
// reset background, foreground and icon // get color of value
if( !(item.value instanceof Color) ) { valueColor = null;
if( item.value instanceof Color )
valueColor = (item.info instanceof Color[]) ? ((Color[])item.info)[0] : (Color) item.value;
else if( item.value instanceof FlatLineBorder )
valueColor = ((FlatLineBorder)item.value).getLineColor();
// reset background and foreground
if( valueColor == null ) {
setBackground( null ); setBackground( null );
setForeground( null ); setForeground( null );
} }
if( !(item.value instanceof Icon) )
setIcon( null );
// value to string // value to string
value = item.getValueAsString(); value = item.getValueAsString();
super.getTableCellRendererComponent( table, value, isSelected, hasFocus, row, column ); super.getTableCellRendererComponent( table, value, isSelected, hasFocus, row, column );
if( item.value instanceof Color ) { // set foreground, if value has color
Color color = (item.info instanceof Color[]) ? ((Color[])item.info)[0] : (Color) item.value; if( valueColor != null ) {
boolean isDark = new HSLColor( color ).getLuminance() < 70 && color.getAlpha() >= 128; boolean isDark = new HSLColor( valueColor ).getLuminance() < 70 && valueColor.getAlpha() >= 128;
valueColor = color;
setForeground( isDark ? Color.white : Color.black ); setForeground( isDark ? Color.white : Color.black );
} else if( item.value instanceof Icon ) { }
// set icon
if( item.value instanceof Icon ) {
Icon icon = (Icon) item.value; Icon icon = (Icon) item.value;
setIcon( new SafeIcon( icon ) ); setIcon( new SafeIcon( icon ) );
} } else
setIcon( null );
// set tooltip // set tooltip
String toolTipText = (item.value instanceof Object[]) String toolTipText = (item.value instanceof Object[])
@@ -1056,7 +1067,7 @@ public class FlatUIDefaultsInspector
@Override @Override
protected void paintComponent( Graphics g ) { protected void paintComponent( Graphics g ) {
if( item.value instanceof Color ) { if( valueColor != null ) {
int width = getWidth(); int width = getWidth();
int height = getHeight(); int height = getHeight();
Color background = valueColor; Color background = valueColor;