/* 当我点击树节点时(EX:WEBLOGIC 被选中)节点图标消失,但其他图标(未选中)来了。请帮我解决这个问题。这是一个基于摇摆的程序 */
class ColorRenderer extends DefaultTreeCellRenderer
{
public ColorRenderer()
{
super();
}
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus)
{
try
{
Component cell = super.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus);
RTGTreeNode treeNode = (RTGTreeNode) value;
GraphUniqueKeyDTO graphUniqueKeyDTO = treeNode.getGraphUniqueKeyDTO();
/*Default Icon not needed.*/
setIcon(null);
if (graphUniqueKeyDTO == null)
{
return cell;
}
String nodeName = treeNode.toString();
if (!leaf)
{
cell.setFont(NSColor.mediumPlainFont());
if (selected)
{
cell.setForeground(Color.black);
cell.setBackground(new Color(128, 0, 0));
}
else
{
Color color = treeNode.getNodeColor();
if (treeNode.getTreeViewToolTip() != null)
nodeName = treeNode.getTreeViewToolTip();
openIcon = treeNode.getImgIcon();
if(openIcon!=null){
setIcon(openIcon);
setLeafIcon(openIcon);
}
if(color == null)
cell.setForeground(NSColor.leftPaneGroupTitleColor());
else
cell.setForeground(color);
}
}
else
{
cell.setFont(NSColor.smallPlainFont());
if (selected)
{
cell.setForeground(Color.black);
cell.setBackground(new Color(128, 0, 0));
}
else
{
cell.setForeground(NSColor.leftPaneGraphTitleColor());
}
}
setToolTipText(nodeName);
JLabel currentCell = (JLabel) cell;
currentCell.setHorizontalAlignment(JLabel.CENTER);
return cell;
}
catch (Exception ex)
{
Log.errorLog("ColorRenderer", "getTreeCellRendererComponent", "", "", "Exception - " + ex);
return null;
}
}