Browse Source

Use correct background color on DefaultTreeCellRenderer.

pull/198/head
weisj 5 years ago
parent
commit
dd866309bc
  1. 19
      core/src/main/java/com/github/weisj/darklaf/ui/cell/CellUtil.java
  2. 1
      core/src/main/java/com/github/weisj/darklaf/ui/tree/DarkTreeCellRendererDelegate.java
  3. 6
      core/src/test/java/ui/table/TableDemo.java
  4. 15
      utils/src/main/java/com/github/weisj/darklaf/util/PropertyUtil.java

19
core/src/main/java/com/github/weisj/darklaf/ui/cell/CellUtil.java

@ -27,7 +27,10 @@ package com.github.weisj.darklaf.ui.cell;
import java.awt.*;
import javax.swing.*;
import javax.swing.plaf.UIResource;
import javax.swing.tree.DefaultTreeCellRenderer;
import com.github.weisj.darklaf.graphics.ColorWrapper;
import com.github.weisj.darklaf.ui.list.DarkListUI;
import com.github.weisj.darklaf.ui.table.DarkTableUI;
import com.github.weisj.darklaf.ui.table.renderer.IconWrapper;
@ -334,7 +337,14 @@ public class CellUtil {
public static void setupTreeBackground(final Component comp, final JTree parent, final boolean selected,
final int row) {
setupBackground(comp, getTreeBackground(comp, parent, selected, row));
Color bg = getTreeBackground(comp, parent, selected, row);
setupBackground(comp, bg);
if (comp instanceof DefaultTreeCellRenderer) {
Color c = comp.getBackground();
if (c == null || c instanceof UIResource || c instanceof NonUIResourceColorWrapper) {
comp.setBackground(new NonUIResourceColorWrapper(bg));
}
}
}
public static Color getTreeBackground(final JTree tree, final boolean selected, final int row) {
@ -554,4 +564,11 @@ public class CellUtil {
Rectangle rect = table.getVisibleRect();
return table.rowAtPoint(rect.getLocation());
}
private static class NonUIResourceColorWrapper extends ColorWrapper {
public NonUIResourceColorWrapper(final Color color) {
super(color);
}
}
}

1
core/src/main/java/com/github/weisj/darklaf/ui/tree/DarkTreeCellRendererDelegate.java

@ -74,6 +74,7 @@ public class DarkTreeCellRendererDelegate extends TreeCellRendererDelegate imple
renderer = super.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, isFocused);
}
CellUtil.setupTreeForeground(renderer, tree, selected);
CellUtil.setupTreeBackground(renderer, tree, selected, row);
return renderer;
}

6
core/src/test/java/ui/table/TableDemo.java

@ -31,14 +31,14 @@ import javax.swing.*;
import javax.swing.table.JTableHeader;
import javax.swing.table.TableCellEditor;
import ui.ComponentDemo;
import ui.DemoPanel;
import com.github.weisj.darklaf.ui.table.DarkTableUI;
import com.github.weisj.darklaf.ui.table.renderer.DarkTableCellEditor;
import com.github.weisj.darklaf.util.PropertyKey;
import com.github.weisj.darklaf.util.PropertyUtil;
import ui.ComponentDemo;
import ui.DemoPanel;
public class TableDemo implements ComponentDemo {
public static void main(final String[] args) {

15
utils/src/main/java/com/github/weisj/darklaf/util/PropertyUtil.java

@ -38,18 +38,12 @@ public class PropertyUtil {
public static void installBackground(final Component component, final Color color) {
if (component == null || color == null) return;
Color c = component.getBackground();
if (c == null || c instanceof UIResource) {
component.setBackground(color);
}
component.setBackground(chooseColor(component.getBackground(), color));
}
public static void installForeground(final Component component, final Color color) {
if (component == null || color == null) return;
Color c = component.getForeground();
if (c == null || c instanceof UIResource) {
component.setForeground(color);
}
component.setForeground(chooseColor(component.getForeground(), color));
}
public static void installBorder(final JComponent component, final Border border) {
@ -187,4 +181,9 @@ public class PropertyUtil {
.map(type::cast)
.collect(Collectors.toList());
}
public static Color chooseColor(final Color currentColor, final Color newColor) {
if (currentColor == null || currentColor instanceof UIResource) return newColor;
return currentColor;
}
}

Loading…
Cancel
Save