From 5ec7848fb0e560e7c45e7d255b6cf7a8ebe865c6 Mon Sep 17 00:00:00 2001 From: Karl Tauber Date: Fri, 3 Jun 2022 17:32:55 +0200 Subject: [PATCH] List: fixed endless loop rounded selection painting --- .../main/java/com/formdev/flatlaf/ui/FlatListUI.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatListUI.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatListUI.java index 792d5068..32e214d4 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatListUI.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatListUI.java @@ -304,7 +304,7 @@ public class FlatListUI // rounded selection or selection insets if( isSelected && - !isFileList && + !isFileList && // rounded selection is not supported for file list rendererComponent instanceof DefaultListCellRenderer && (selectionArc > 0 || (selectionInsets != null && @@ -319,6 +319,10 @@ public class FlatListUI // To solve this, a graphics proxy is used that paints rounded selection // if row is selected and the renderer wants to fill the background. class RoundedSelectionGraphics extends Graphics2DProxy { + // used to avoid endless loop in case that paintCellSelection() invokes + // g.fillRect() with full bounds (selectionInsets is 0,0,0,0) + private boolean inPaintSelection; + RoundedSelectionGraphics( Graphics delegate ) { super( (Graphics2D) delegate ); } @@ -335,10 +339,13 @@ public class FlatListUI @Override public void fillRect( int x, int y, int width, int height ) { - if( x == 0 && y == 0 && width == rowBounds.width && height == rowBounds.height && + if( !inPaintSelection && + x == 0 && y == 0 && width == rowBounds.width && height == rowBounds.height && this.getColor() == rendererComponent.getBackground() ) { + inPaintSelection = true; paintCellSelection( this, row, x, y, width, height ); + inPaintSelection = false; } else super.fillRect( x, y, width, height ); }