diff --git a/core/src/main/java/com/github/weisj/darklaf/ui/cell/CellUtil.java b/core/src/main/java/com/github/weisj/darklaf/ui/cell/CellUtil.java index ac1865bc..6d254847 100644 --- a/core/src/main/java/com/github/weisj/darklaf/ui/cell/CellUtil.java +++ b/core/src/main/java/com/github/weisj/darklaf/ui/cell/CellUtil.java @@ -311,22 +311,34 @@ public final class CellUtil { setupBackground(comp, getTableBackground(comp, parent, selected, hasFocus(parent, comp), row)); } + public static Color getTreeBackground(final JTree tree, final boolean selected, final int row) { + return getTreeBackground(tree, tree, selected, hasFocus(tree, tree), row); + } + public static Color getTreeBackground(final Component comp, final JTree parent, final boolean selected, final boolean focus, final int row) { - boolean alt = row % 2 == 1 && PropertyUtil.getBooleanProperty(parent, DarkTreeUI.KEY_ALTERNATE_ROW_COLOR); - return getColor(comp, focus, selected, alt ? treeCellBackgroundAlternative : treeCellBackground, - treeCellBackgroundSelected, alt ? treeCellBackgroundNoFocusAlternative : treeCellBackgroundNoFocus, + Color treeBg = parent.getBackground(); + boolean canOverwrite = ColorUtil.canOverwriteColor(treeBg); + boolean alt = canOverwrite && row % 2 == 1 + && PropertyUtil.getBooleanProperty(parent, DarkTreeUI.KEY_ALTERNATE_ROW_COLOR); + Color defaultBg = canOverwrite ? treeCellBackground : treeBg; + Color defaultBgNoFocus = canOverwrite ? treeCellBackgroundNoFocus : treeBg; + Color defaultBgInactive = canOverwrite ? treeCellInactiveBackground : treeBg; + Color defaultBgInactiveNoFocus = canOverwrite ? treeCellInactiveBackgroundNoFocus : treeBg; + return getColor(comp.isEnabled(), focus, selected, + alt ? treeCellBackgroundAlternative : defaultBg, treeCellBackgroundSelected, + alt ? treeCellBackgroundNoFocusAlternative : defaultBgNoFocus, treeCellBackgroundSelectedNoFocus, - alt ? treeCellInactiveBackgroundAlternative : treeCellInactiveBackground, + alt ? treeCellInactiveBackgroundAlternative : defaultBgInactive, treeCellInactiveBackgroundSelected, - alt ? treeCellInactiveBackgroundNoFocusAlternative : treeCellInactiveBackgroundNoFocus, + alt ? treeCellInactiveBackgroundNoFocusAlternative : defaultBgInactiveNoFocus, treeCellInactiveBackgroundSelectedNoFocus); } public static void setupTreeBackground(final Component comp, final JTree parent, final boolean selected, final int row) { Color bg = getTreeBackground(comp, parent, selected, hasFocus(parent, comp), row); - setupBackground(comp, bg); + comp.setBackground(bg); if (comp instanceof DefaultTreeCellRenderer) { Color c = comp.getBackground(); if (ColorUtil.canOverwriteColor(c)) { @@ -335,18 +347,6 @@ public final class CellUtil { } } - public static Color getTreeBackground(final JTree tree, final boolean selected, final int row) { - boolean alt = row % 2 == 1 && PropertyUtil.getBooleanProperty(tree, DarkTreeUI.KEY_ALTERNATE_ROW_COLOR); - return getColor(tree.isEnabled(), hasFocus(tree, tree), selected, - alt ? treeCellBackgroundAlternative : treeCellBackground, treeCellBackgroundSelected, - alt ? treeCellBackgroundNoFocusAlternative : treeCellBackgroundNoFocus, - treeCellBackgroundSelectedNoFocus, - alt ? treeCellInactiveBackgroundAlternative : treeCellInactiveBackground, - treeCellInactiveBackgroundSelected, - alt ? treeCellInactiveBackgroundNoFocusAlternative : treeCellInactiveBackgroundNoFocus, - treeCellInactiveBackgroundSelectedNoFocus); - } - public static Color getListBackground(final Component comp, final JList parent, final boolean selected, final int index) { int layout = parent.getLayoutOrientation();