diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTreeUI.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTreeUI.java index 6eecb7518..db0cc8217 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTreeUI.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTreeUI.java @@ -102,6 +102,7 @@ * @uiDefault Tree.selectionForeground Color * @uiDefault Tree.selectionInactiveBackground Color * @uiDefault Tree.selectionInactiveForeground Color + * @uiDefault Tree.alternateRowColor Color * @uiDefault Tree.selectionInsets Insets * @uiDefault Tree.selectionArc int * @uiDefault Tree.wideSelection boolean @@ -141,6 +142,7 @@ public class FlatTreeUI @Styleable protected Color selectionInactiveBackground; @Styleable protected Color selectionInactiveForeground; @Styleable protected Color selectionBorderColor; + @Styleable protected Color alternateRowColor; /** @since 3 */ @Styleable protected Insets selectionInsets; /** @since 3 */ @Styleable protected int selectionArc; @Styleable protected boolean wideSelection; @@ -192,6 +194,7 @@ protected void installDefaults() { selectionInactiveBackground = UIManager.getColor( "Tree.selectionInactiveBackground" ); selectionInactiveForeground = UIManager.getColor( "Tree.selectionInactiveForeground" ); selectionBorderColor = UIManager.getColor( "Tree.selectionBorderColor" ); + alternateRowColor = UIManager.getColor( "Tree.alternateRowColor" ); selectionInsets = UIManager.getInsets( "Tree.selectionInsets" ); selectionArc = UIManager.getInt( "Tree.selectionArc" ); wideSelection = UIManager.getBoolean( "Tree.wideSelection" ); @@ -227,6 +230,7 @@ protected void uninstallDefaults() { selectionInactiveBackground = null; selectionInactiveForeground = null; selectionBorderColor = null; + alternateRowColor = null; defaultLeafIcon = null; defaultClosedIcon = null; @@ -570,6 +574,11 @@ protected void paintRow( Graphics g, Rectangle clipBounds, Insets insets, Rectan boolean isSelected = tree.isRowSelected( row ); boolean isDropRow = isDropRow( row ); boolean needsSelectionPainting = (isSelected || isDropRow) && isPaintSelection(); + + if( alternateRowColor != null && row % 2 != 0 ) { + g.setColor( alternateRowColor ); + FlatUIUtils.paintComponentBackground((Graphics2D) g, bounds.x, bounds.y, tree.getWidth(), bounds.height, 0, 0); + } // do not paint row if editing if( isEditing ) { diff --git a/flatlaf-core/src/test/java/com/formdev/flatlaf/ui/TestFlatStyleableInfo.java b/flatlaf-core/src/test/java/com/formdev/flatlaf/ui/TestFlatStyleableInfo.java index ea536a16c..8058bed2a 100644 --- a/flatlaf-core/src/test/java/com/formdev/flatlaf/ui/TestFlatStyleableInfo.java +++ b/flatlaf-core/src/test/java/com/formdev/flatlaf/ui/TestFlatStyleableInfo.java @@ -965,6 +965,7 @@ void tree() { "selectionInactiveBackground", Color.class, "selectionInactiveForeground", Color.class, "selectionBorderColor", Color.class, + "alternateRowColor", Color.class, "selectionInsets", Insets.class, "selectionArc", int.class, "wideSelection", boolean.class, diff --git a/flatlaf-theme-editor/src/main/resources/com/formdev/flatlaf/themeeditor/FlatLafUIKeys.txt b/flatlaf-theme-editor/src/main/resources/com/formdev/flatlaf/themeeditor/FlatLafUIKeys.txt index 60549ff45..b42eba607 100644 --- a/flatlaf-theme-editor/src/main/resources/com/formdev/flatlaf/themeeditor/FlatLafUIKeys.txt +++ b/flatlaf-theme-editor/src/main/resources/com/formdev/flatlaf/themeeditor/FlatLafUIKeys.txt @@ -1182,6 +1182,7 @@ Tree.dropCellForeground Tree.dropLineColor Tree.editorBorder Tree.editorBorderSelectionColor +Tree.alternateRowColor Tree.expandedIcon Tree.focusInputMap Tree.focusInputMap.RightToLeft