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)

This commit is contained in:
Karl Tauber
2023-02-02 11:50:13 +01:00
parent 29b801e13d
commit 28cdde3f17
4 changed files with 58 additions and 11 deletions

View File

@@ -310,6 +310,21 @@ public class FlatTreeUI
tree.revalidate();
tree.repaint();
break;
case "enabled":
// if default icons are not shown and the renderer is a subclass
// of DefaultTreeCellRenderer, then invalidate tree node sizes
// because the custom renderer may use an icon for enabled state
// but none for disabled state
if( !showDefaultIcons &&
currentCellRenderer instanceof DefaultTreeCellRenderer &&
currentCellRenderer.getClass() != DefaultTreeCellRenderer.class &&
treeState != null )
{
treeState.invalidateSizes();
updateSize();
}
break;
}
}
};
@@ -695,7 +710,7 @@ public class FlatTreeUI
if( rendererComponent instanceof JLabel ) {
JLabel label = (JLabel) rendererComponent;
Icon icon = label.getIcon();
Icon icon = label.isEnabled() ? label.getIcon() : label.getDisabledIcon();
imageOffset = (icon != null && label.getText() != null)
? icon.getIconWidth() + Math.max( label.getIconTextGap() - 1, 0 )
: 0;