mirror of
https://github.com/JFormDesigner/FlatLaf.git
synced 2026-02-10 22:17:13 -06:00
Merge PR #939: Support for alternate row color in JList
This commit is contained in:
@@ -57,6 +57,7 @@ import com.formdev.flatlaf.util.UIScale;
|
|||||||
* @uiDefault List.foreground Color
|
* @uiDefault List.foreground Color
|
||||||
* @uiDefault List.selectionBackground Color
|
* @uiDefault List.selectionBackground Color
|
||||||
* @uiDefault List.selectionForeground Color
|
* @uiDefault List.selectionForeground Color
|
||||||
|
* @uiDefault List.alternateRowColor Color
|
||||||
* @uiDefault List.dropLineColor Color
|
* @uiDefault List.dropLineColor Color
|
||||||
* @uiDefault List.border Border
|
* @uiDefault List.border Border
|
||||||
* @uiDefault List.cellRenderer ListCellRenderer
|
* @uiDefault List.cellRenderer ListCellRenderer
|
||||||
@@ -93,6 +94,7 @@ public class FlatListUI
|
|||||||
@Styleable protected Color selectionForeground;
|
@Styleable protected Color selectionForeground;
|
||||||
@Styleable protected Color selectionInactiveBackground;
|
@Styleable protected Color selectionInactiveBackground;
|
||||||
@Styleable protected Color selectionInactiveForeground;
|
@Styleable protected Color selectionInactiveForeground;
|
||||||
|
/** @since 3.6 */ @Styleable protected Color alternateRowColor;
|
||||||
/** @since 3 */ @Styleable protected Insets selectionInsets;
|
/** @since 3 */ @Styleable protected Insets selectionInsets;
|
||||||
/** @since 3 */ @Styleable protected int selectionArc;
|
/** @since 3 */ @Styleable protected int selectionArc;
|
||||||
|
|
||||||
@@ -129,6 +131,7 @@ public class FlatListUI
|
|||||||
selectionForeground = UIManager.getColor( "List.selectionForeground" );
|
selectionForeground = UIManager.getColor( "List.selectionForeground" );
|
||||||
selectionInactiveBackground = UIManager.getColor( "List.selectionInactiveBackground" );
|
selectionInactiveBackground = UIManager.getColor( "List.selectionInactiveBackground" );
|
||||||
selectionInactiveForeground = UIManager.getColor( "List.selectionInactiveForeground" );
|
selectionInactiveForeground = UIManager.getColor( "List.selectionInactiveForeground" );
|
||||||
|
alternateRowColor = UIManager.getColor( "List.alternateRowColor" );
|
||||||
selectionInsets = UIManager.getInsets( "List.selectionInsets" );
|
selectionInsets = UIManager.getInsets( "List.selectionInsets" );
|
||||||
selectionArc = UIManager.getInt( "List.selectionArc" );
|
selectionArc = UIManager.getInt( "List.selectionArc" );
|
||||||
|
|
||||||
@@ -143,6 +146,7 @@ public class FlatListUI
|
|||||||
selectionForeground = null;
|
selectionForeground = null;
|
||||||
selectionInactiveBackground = null;
|
selectionInactiveBackground = null;
|
||||||
selectionInactiveForeground = null;
|
selectionInactiveForeground = null;
|
||||||
|
alternateRowColor = null;
|
||||||
|
|
||||||
oldStyleValues = null;
|
oldStyleValues = null;
|
||||||
}
|
}
|
||||||
@@ -319,6 +323,18 @@ public class FlatListUI
|
|||||||
cw = rowBounds.width;
|
cw = rowBounds.width;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// combobox does not support alternate row color
|
||||||
|
if( !"ComboBox.list".equals( list.getName() ) ) {
|
||||||
|
if( alternateRowColor != null && row % 2 != 0 ) {
|
||||||
|
g.setColor( alternateRowColor );
|
||||||
|
|
||||||
|
// paint respecting selection arc
|
||||||
|
float arc = UIScale.scale( selectionArc / 2f );
|
||||||
|
FlatUIUtils.paintSelection( (Graphics2D) g, 0, rowBounds.y, list.getWidth(), rowBounds.height,
|
||||||
|
UIScale.scale( selectionInsets ), arc, arc, arc, arc, 0 );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// rounded selection or selection insets
|
// rounded selection or selection insets
|
||||||
if( isSelected &&
|
if( isSelected &&
|
||||||
!isFileList && // rounded selection is not supported for file list
|
!isFileList && // rounded selection is not supported for file list
|
||||||
|
|||||||
@@ -270,6 +270,7 @@ public class TestFlatStyleableInfo
|
|||||||
"selectionForeground", Color.class,
|
"selectionForeground", Color.class,
|
||||||
"selectionInactiveBackground", Color.class,
|
"selectionInactiveBackground", Color.class,
|
||||||
"selectionInactiveForeground", Color.class,
|
"selectionInactiveForeground", Color.class,
|
||||||
|
"alternateRowColor", Color.class,
|
||||||
"selectionInsets", Insets.class,
|
"selectionInsets", Insets.class,
|
||||||
"selectionArc", int.class,
|
"selectionArc", int.class,
|
||||||
|
|
||||||
|
|||||||
@@ -370,6 +370,7 @@ public class TestFlatStyleableValue
|
|||||||
testColor( c, ui, "selectionForeground", 0x123456 );
|
testColor( c, ui, "selectionForeground", 0x123456 );
|
||||||
testColor( c, ui, "selectionInactiveBackground", 0x123456 );
|
testColor( c, ui, "selectionInactiveBackground", 0x123456 );
|
||||||
testColor( c, ui, "selectionInactiveForeground", 0x123456 );
|
testColor( c, ui, "selectionInactiveForeground", 0x123456 );
|
||||||
|
testColor( c, ui, "alternateRowColor", 0x123456 );
|
||||||
testInsets( c, ui, "selectionInsets", 1,2,3,4 );
|
testInsets( c, ui, "selectionInsets", 1,2,3,4 );
|
||||||
testInteger( c, ui, "selectionArc", 123 );
|
testInteger( c, ui, "selectionArc", 123 );
|
||||||
|
|
||||||
|
|||||||
@@ -433,6 +433,7 @@ public class TestFlatStyling
|
|||||||
ui.applyStyle( "selectionForeground: #fff" );
|
ui.applyStyle( "selectionForeground: #fff" );
|
||||||
ui.applyStyle( "selectionInactiveBackground: #fff" );
|
ui.applyStyle( "selectionInactiveBackground: #fff" );
|
||||||
ui.applyStyle( "selectionInactiveForeground: #fff" );
|
ui.applyStyle( "selectionInactiveForeground: #fff" );
|
||||||
|
ui.applyStyle( "alternateRowColor: #fff" );
|
||||||
ui.applyStyle( "selectionInsets: 1,2,3,4" );
|
ui.applyStyle( "selectionInsets: 1,2,3,4" );
|
||||||
ui.applyStyle( "selectionArc: 8" );
|
ui.applyStyle( "selectionArc: 8" );
|
||||||
|
|
||||||
|
|||||||
@@ -469,6 +469,7 @@ Label.disabledShadow
|
|||||||
Label.font
|
Label.font
|
||||||
Label.foreground
|
Label.foreground
|
||||||
LabelUI
|
LabelUI
|
||||||
|
List.alternateRowColor
|
||||||
List.background
|
List.background
|
||||||
List.border
|
List.border
|
||||||
List.cellFocusColor
|
List.cellFocusColor
|
||||||
|
|||||||
Reference in New Issue
Block a user