- fixed wrong x/width bounds of alternating rows for multi-column lists (PR #939)
- Demo: added "alternating rows" checkboxes to "Data Components" page
This commit is contained in:
Karl Tauber
2024-12-18 12:22:04 +01:00
parent 7027821c00
commit 80ba75fdeb
6 changed files with 214 additions and 31 deletions

View File

@@ -303,13 +303,24 @@ public class FlatListUI
{
boolean isSelected = selModel.isSelectedIndex( row );
// paint alternating rows
if( alternateRowColor != null && row % 2 != 0 &&
!"ComboBox.list".equals( list.getName() ) ) // combobox does not support alternate row color
{
g.setColor( alternateRowColor );
float arc = UIScale.scale( selectionArc / 2f );
FlatUIUtils.paintSelection( (Graphics2D) g, rowBounds.x, rowBounds.y, rowBounds.width, rowBounds.height,
UIScale.scale( selectionInsets ), arc, arc, arc, arc, 0 );
}
// get renderer component
@SuppressWarnings( "unchecked" )
Component rendererComponent = cellRenderer.getListCellRendererComponent( list,
dataModel.getElementAt( row ), row, isSelected,
FlatUIUtils.isPermanentFocusOwner( list ) && (row == leadIndex) );
//
// use smaller cell width if list is used in JFileChooser
boolean isFileList = Boolean.TRUE.equals( list.getClientProperty( "List.isFileList" ) );
int cx, cw;
if( isFileList ) {
@@ -323,18 +334,6 @@ public class FlatListUI
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
if( isSelected &&
!isFileList && // rounded selection is not supported for file list