mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2025-12-06 14:00:55 +03:00
new: support for alternate row color in jtree
see: https://github.com/JFormDesigner/FlatLaf/issues/900
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -1182,6 +1182,7 @@ Tree.dropCellForeground
|
||||
Tree.dropLineColor
|
||||
Tree.editorBorder
|
||||
Tree.editorBorderSelectionColor
|
||||
Tree.alternateRowColor
|
||||
Tree.expandedIcon
|
||||
Tree.focusInputMap
|
||||
Tree.focusInputMap.RightToLeft
|
||||
|
||||
Reference in New Issue
Block a user