Skip to content

Commit

Permalink
mod: combobox does not support alternate row color
Browse files Browse the repository at this point in the history
  • Loading branch information
dar-dev committed Dec 13, 2024
1 parent c12adf1 commit 19055d5
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatListUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.awt.event.FocusListener;
import java.beans.PropertyChangeListener;
import java.util.Map;
import javax.swing.DefaultComboBoxModel;
import javax.swing.DefaultListCellRenderer;
import javax.swing.JComponent;
import javax.swing.JList;
Expand Down Expand Up @@ -308,16 +309,7 @@ protected void paintCell( Graphics g, int row, Rectangle rowBounds, ListCellRend
Component rendererComponent = cellRenderer.getListCellRendererComponent( list,
dataModel.getElementAt( row ), row, isSelected,
FlatUIUtils.isPermanentFocusOwner( list ) && (row == leadIndex) );

if( alternateRowColor != null && row % 2 != 0 ) {
g.setColor( alternateRowColor );

// paint respecting selection arc
final 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 );
}


//
boolean isFileList = Boolean.TRUE.equals( list.getClientProperty( "List.isFileList" ) );
int cx, cw;
Expand All @@ -331,6 +323,18 @@ protected void paintCell( Graphics g, int row, Rectangle rowBounds, ListCellRend
cx = rowBounds.x;
cw = rowBounds.width;
}

// filelist/combobox does not support alternate row color
if( !isFileList && !(dataModel instanceof DefaultComboBoxModel) ) {
if( alternateRowColor != null && row % 2 != 0 ) {
g.setColor( alternateRowColor );

// paint respecting selection arc
final 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 &&
Expand Down

0 comments on commit 19055d5

Please sign in to comment.