Tree: fill cell background if DefaultTreeCellRenderer.setBackgroundNonSelectionColor(Color) was used (issue #322)

This commit is contained in:
Karl Tauber
2021-05-12 15:45:36 +02:00
parent 03b42749cd
commit 38a3a0768d
3 changed files with 56 additions and 14 deletions

View File

@@ -1200,10 +1200,27 @@ public class FlatComponents2Test
extends DefaultTreeCellRenderer
{
public TestDefaultTreeCellRenderer() {
setBackgroundNonSelectionColor( Color.red );
setBackgroundSelectionColor( Color.green );
setTextSelectionColor( Color.blue );
}
@Override
public Component getTreeCellRendererComponent( JTree tree, Object value, boolean sel, boolean expanded,
boolean leaf, int row, boolean hasFocus )
{
Color nonSelectionBg = null;
Color nonSelectionFg = null;
switch( String.valueOf( value ) ) {
case "blue": nonSelectionFg = Color.blue; break;
case "red": nonSelectionFg = Color.red; break;
case "yellow": nonSelectionBg = Color.yellow; break;
case "violet": nonSelectionBg = Color.magenta; break;
}
setBackgroundNonSelectionColor( nonSelectionBg );
setTextNonSelectionColor( (nonSelectionFg != null) ? nonSelectionFg : UIManager.getColor( "Tree.textForeground" ) );
return super.getTreeCellRendererComponent( tree, value, sel, expanded, leaf, row, hasFocus );
}
}
//---- class TestLabelTreeCellRenderer ------------------------------------