Browse Source

Don't pass null values for background rendering to user defined renderers.

pull/235/head
weisj 4 years ago
parent
commit
867803af6f
No known key found for this signature in database
GPG Key ID: 31124CB75461DA2A
  1. 6
      core/src/main/java/com/github/weisj/darklaf/ui/list/DarkListCellRendererDelegate.java
  2. 8
      core/src/main/java/com/github/weisj/darklaf/ui/list/DarkListUI.java
  3. 6
      core/src/test/java/icon/AllIcons.java

6
core/src/main/java/com/github/weisj/darklaf/ui/list/DarkListCellRendererDelegate.java

@ -27,10 +27,14 @@ import javax.swing.*;
import com.github.weisj.darklaf.delegate.ListCellRendererDelegate;
import com.github.weisj.darklaf.ui.cell.CellUtil;
import com.github.weisj.darklaf.util.LazyValue;
import com.github.weisj.darklaf.util.PropertyUtil;
public class DarkListCellRendererDelegate extends ListCellRendererDelegate<Object> implements SwingConstants {
private static final LazyValue<DefaultListCellRenderer> DEFAULT_RENDERER =
new LazyValue<>(DefaultListCellRenderer::new);
public DarkListCellRendererDelegate() {
super(null);
}
@ -38,7 +42,7 @@ public class DarkListCellRendererDelegate extends ListCellRendererDelegate<Objec
@Override
public void setDelegate(final ListCellRenderer<Object> delegate) {
if (delegate == null) {
super.setDelegate(new DefaultListCellRenderer());
super.setDelegate(DEFAULT_RENDERER.get());
} else {
super.setDelegate(delegate);
}

8
core/src/main/java/com/github/weisj/darklaf/ui/list/DarkListUI.java

@ -184,8 +184,14 @@ public class DarkListUI extends DarkListUIBridge implements CellConstants {
int cw = empty && bgWidth > 0 ? bgWidth : rowBounds.width;
int ch = rowBounds.height;
ListCellRenderer<Object> renderer = cellRenderer;
if (empty) {
rendererDelegate.setDelegate(null);
renderer = rendererDelegate;
}
Component rendererComponent =
cellRenderer.getListCellRendererComponent(list, value, cellIndex, isSelected, cellHasFocus);
renderer.getListCellRendererComponent(list, value, cellIndex, isSelected, cellHasFocus);
rendererPane.paintComponent(g, rendererComponent, list, cx, cy, cw, ch, true);
}

6
core/src/test/java/icon/AllIcons.java

@ -152,10 +152,8 @@ public class AllIcons implements ComponentDemo {
public Component getListCellRendererComponent(final JList<? extends Pair<String, ? extends Icon>> list,
final Pair<String, ? extends Icon> value, final int index, final boolean isSelected,
final boolean cellHasFocus) {
if (value != null) {
setIcon(value.getSecond());
setText(value.getFirst());
}
setIcon(value.getSecond());
setText(value.getFirst());
return this;
}
}

Loading…
Cancel
Save