new: support for alternate row color in jtree

see: https://github.com/JFormDesigner/FlatLaf/issues/900
This commit is contained in:
Dar
2024-10-22 16:46:30 +02:00
parent c29a276188
commit 33e37a7167
3 changed files with 11 additions and 0 deletions

View File

@@ -102,6 +102,7 @@ import com.formdev.flatlaf.util.UIScale;
* @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 @@ public class FlatTreeUI
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 @@ public class FlatTreeUI
selectionInactiveBackground = null;
selectionInactiveForeground = null;
selectionBorderColor = null;
alternateRowColor = null;
defaultLeafIcon = null;
defaultClosedIcon = null;
@@ -571,6 +575,11 @@ public class FlatTreeUI
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 ) {
// paint wide selection

View File

@@ -965,6 +965,7 @@ public class TestFlatStyleableInfo
"selectionInactiveBackground", Color.class,
"selectionInactiveForeground", Color.class,
"selectionBorderColor", Color.class,
"alternateRowColor", Color.class,
"selectionInsets", Insets.class,
"selectionArc", int.class,
"wideSelection", boolean.class,

View File

@@ -1182,6 +1182,7 @@ Tree.dropCellForeground
Tree.dropLineColor
Tree.editorBorder
Tree.editorBorderSelectionColor
Tree.alternateRowColor
Tree.expandedIcon
Tree.focusInputMap
Tree.focusInputMap.RightToLeft