Skip to content

Commit b251ff7

Browse files
committed
Merge PR #1080: Fix NPE in FlatUIDefaultsInspector when color is null
2 parents ea2a985 + 3ca7ebb commit b251ff7

File tree

2 files changed

+26
-11
lines changed

2 files changed

+26
-11
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ FlatLaf Change Log
88
- Popup: Fixed scrolling popup painting issue on Windows 10 when a glass pane is
99
visible and frame is maximized. (issue #1071)
1010
- ToolBar: Grip disappeared when switching between Look and Feels. (issue #1075)
11+
- Extras:
12+
- UI defaults inspector: Fixed NPE if color of `FlatLineBorder` is null. Also
13+
use `FlatLineBorder` line color as cell background color in "Value" column.
14+
(PR #1080)
1115

1216

1317
## 3.7

flatlaf-extras/src/main/java/com/formdev/flatlaf/extras/FlatUIDefaultsInspector.java

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -777,6 +777,9 @@ else if( value instanceof int[] )
777777

778778
@SuppressWarnings( "FormatString" ) // Error Prone
779779
private static String color2hex( Color color ) {
780+
if( color == null )
781+
return "";
782+
780783
int rgb = color.getRGB();
781784
boolean hasAlpha = color.getAlpha() != 255;
782785

@@ -1018,28 +1021,36 @@ public Component getTableCellRendererComponent( JTable table, Object value,
10181021
item = (Item) value;
10191022
init( table, item.key, isSelected, row );
10201023

1021-
// reset background, foreground and icon
1022-
if( !(item.value instanceof Color) ) {
1024+
// get color of value
1025+
valueColor = null;
1026+
if( item.value instanceof Color )
1027+
valueColor = (item.info instanceof Color[]) ? ((Color[])item.info)[0] : (Color) item.value;
1028+
else if( item.value instanceof FlatLineBorder )
1029+
valueColor = ((FlatLineBorder)item.value).getLineColor();
1030+
1031+
// reset background and foreground
1032+
if( valueColor == null ) {
10231033
setBackground( null );
10241034
setForeground( null );
10251035
}
1026-
if( !(item.value instanceof Icon) )
1027-
setIcon( null );
10281036

10291037
// value to string
10301038
value = item.getValueAsString();
10311039

10321040
super.getTableCellRendererComponent( table, value, isSelected, hasFocus, row, column );
10331041

1034-
if( item.value instanceof Color ) {
1035-
Color color = (item.info instanceof Color[]) ? ((Color[])item.info)[0] : (Color) item.value;
1036-
boolean isDark = new HSLColor( color ).getLuminance() < 70 && color.getAlpha() >= 128;
1037-
valueColor = color;
1042+
// set foreground, if value has color
1043+
if( valueColor != null ) {
1044+
boolean isDark = new HSLColor( valueColor ).getLuminance() < 70 && valueColor.getAlpha() >= 128;
10381045
setForeground( isDark ? Color.white : Color.black );
1039-
} else if( item.value instanceof Icon ) {
1046+
}
1047+
1048+
// set icon
1049+
if( item.value instanceof Icon ) {
10401050
Icon icon = (Icon) item.value;
10411051
setIcon( new SafeIcon( icon ) );
1042-
}
1052+
} else
1053+
setIcon( null );
10431054

10441055
// set tooltip
10451056
String toolTipText = (item.value instanceof Object[])
@@ -1056,7 +1067,7 @@ public Component getTableCellRendererComponent( JTable table, Object value,
10561067

10571068
@Override
10581069
protected void paintComponent( Graphics g ) {
1059-
if( item.value instanceof Color ) {
1070+
if( valueColor != null ) {
10601071
int width = getWidth();
10611072
int height = getHeight();
10621073
Color background = valueColor;

0 commit comments

Comments
 (0)