我会简短点;我想将JTree的颜色从Metal LF的默认蓝色更改为灰色。我已经看过ExtendedJTreeCellRenderer了。可以使用UIManager完成此操作,如果不需要自定义图标树就可以完成此操作?我有10多年使用Java的经验,谢谢。
public static class ExtendedJTreeCellRenderer extends DefaultTreeCellRenderer
{
@Override
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean isSelected, boolean expanded, boolean leaf, int row, boolean hasFocus)
{
JComponent c = (JComponent) super.getTreeCellRendererComponent(tree, value, isSelected, expanded, leaf, row, hasFocus);
Graphics graphics = c.getGraphics();
if(graphics!=null) graphics.setColor(Color.GRAY);
c.setForeground(new Color(140,140,140));
c.setBackground(new Color(8,8,8));
c.setFont(new Font("Georgia", Font.PLAIN, 12));
c.setOpaque(true);
//
this.setClosedIcon(new ImageIcon("images\\folder001.png"));
//this.setOpenIcon(new ImageIcon(""));
//this.setLeafIcon(new ImageIcon(""));
//
return c;
}
}