diff --git a/CHANGELOG.md b/CHANGELOG.md index 488b0962..8c234a2d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -38,6 +38,9 @@ FlatLaf Change Log - Updated "Hiberbee Dark" and "Material Theme UI Lite" themes. - Styling: Fixed resolving of UI variables in styles that use other variables. - MenuItem: Fixed horizontal alignment of icons. (issue #631) +- Tree: Fixed missing custom closed/opened/leaf icons of a custom + `DefaultTreeCellRenderer`. (issue #653; regression since implementing PR #609 + in FlatLaf 3.0) - Tree: Fixed truncated node text and too small painted non-wide node background if custom cell renderer sets icon, but not disabled icon, and tree is disabled. (issue #640) diff --git a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTreeUI.java b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTreeUI.java index db52cd36..5a1ca8f2 100644 --- a/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTreeUI.java +++ b/flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatTreeUI.java @@ -158,6 +158,10 @@ public class FlatTreeUI // only used via styling (not in UI defaults, but has likewise client properties) /** @since 2 */ @Styleable protected boolean paintSelection = true; + private Icon defaultLeafIcon; + private Icon defaultClosedIcon; + private Icon defaultOpenIcon; + private boolean paintLines; private Color defaultCellNonSelectionBackground; private Color defaultSelectionBackground; @@ -193,6 +197,10 @@ public class FlatTreeUI showCellFocusIndicator = UIManager.getBoolean( "Tree.showCellFocusIndicator" ); showDefaultIcons = UIManager.getBoolean( "Tree.showDefaultIcons" ); + defaultLeafIcon = UIManager.getIcon( "Tree.leafIcon" ); + defaultClosedIcon = UIManager.getIcon( "Tree.closedIcon" ); + defaultOpenIcon = UIManager.getIcon( "Tree.openIcon" ); + paintLines = UIManager.getBoolean( "Tree.paintLines" ); defaultCellNonSelectionBackground = UIManager.getColor( "Tree.textBackground" ); defaultSelectionBackground = selectionBackground; @@ -219,6 +227,10 @@ public class FlatTreeUI selectionInactiveForeground = null; selectionBorderColor = null; + defaultLeafIcon = null; + defaultClosedIcon = null; + defaultOpenIcon = null; + defaultCellNonSelectionBackground = null; defaultSelectionBackground = null; defaultSelectionForeground = null; @@ -233,9 +245,14 @@ public class FlatTreeUI // remove default leaf/closed/opened icons if( !showDefaultIcons && currentCellRenderer instanceof DefaultTreeCellRenderer ) { DefaultTreeCellRenderer renderer = (DefaultTreeCellRenderer) currentCellRenderer; - renderer.setLeafIcon( null ); - renderer.setClosedIcon( null ); - renderer.setOpenIcon( null ); + if( renderer.getLeafIcon() == defaultLeafIcon && + renderer.getClosedIcon() == defaultClosedIcon && + renderer.getOpenIcon() == defaultOpenIcon ) + { + renderer.setLeafIcon( null ); + renderer.setClosedIcon( null ); + renderer.setOpenIcon( null ); + } } } diff --git a/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/FlatComponents2Test.java b/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/FlatComponents2Test.java index 74836658..f4721eba 100644 --- a/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/FlatComponents2Test.java +++ b/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/FlatComponents2Test.java @@ -439,6 +439,11 @@ public class FlatComponents2Test tree.setCellRenderer( new TestDefaultTreeCellRenderer() ); break; + case "defaultWithIcons": + for( JTree tree : trees ) + tree.setCellRenderer( new TestDefaultWithIconsTreeCellRenderer() ); + break; + case "defaultWithIcon": for( JTree tree : trees ) tree.setCellRenderer( new TestDefaultWithIconTreeCellRenderer() ); @@ -960,6 +965,7 @@ public class FlatComponents2Test treeRendererComboBox.setModel(new DefaultComboBoxModel<>(new String[] { "default", "defaultSubclass", + "defaultWithIcons", "defaultWithIcon", "label", "swingxDefault", @@ -1612,6 +1618,18 @@ public class FlatComponents2Test } } + //---- class TestDefaultWithIconsTreeCellRenderer ------------------------- + + private static class TestDefaultWithIconsTreeCellRenderer + extends TestDefaultTreeCellRenderer + { + public TestDefaultWithIconsTreeCellRenderer() { + setLeafIcon( UIManager.getIcon( "FileView.floppyDriveIcon" ) ); + setClosedIcon( UIManager.getIcon( "FileView.hardDriveIcon" ) ); + setOpenIcon( UIManager.getIcon( "FileView.computerIcon" ) ); + } + } + //---- class TestDefaultWithIconTreeCellRenderer -------------------------- private static class TestDefaultWithIconTreeCellRenderer diff --git a/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/FlatComponents2Test.jfd b/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/FlatComponents2Test.jfd index d2a79ac5..066ca1c9 100644 --- a/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/FlatComponents2Test.jfd +++ b/flatlaf-testing/src/main/java/com/formdev/flatlaf/testing/FlatComponents2Test.jfd @@ -411,6 +411,7 @@ new FormModel { selectedItem: "default" addElement( "default" ) addElement( "defaultSubclass" ) + addElement( "defaultWithIcons" ) addElement( "defaultWithIcon" ) addElement( "label" ) addElement( "swingxDefault" )