package fenetres; import java.awt.Color; import java.awt.Component; import java.awt.Font; import javax.swing.ImageIcon; import javax.swing.JTree; import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.DefaultTreeCellRenderer; import cXML.node; public class MyTreeCellRenderer extends DefaultTreeCellRenderer { /** * */ private static final long serialVersionUID = 1L; @Override public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean exp, boolean leaf, int row, boolean hasFocus) { super.getTreeCellRendererComponent(tree, value, sel, exp, leaf, row, hasFocus); DefaultTreeCellRenderer cellRenderer = (DefaultTreeCellRenderer) tree.getCellRenderer(); cellRenderer.setOpenIcon(new ImageIcon(create.class.getResource("/resources/treeOpen.png"))); cellRenderer.setClosedIcon(new ImageIcon(create.class.getResource("/resources/treeClose.png"))); cellRenderer.setLeafIcon(new ImageIcon(create.class.getResource("/resources/treeLeaf.png"))); cellRenderer.setBackgroundNonSelectionColor(new Color(255, 255, 255)); cellRenderer.setBackgroundSelectionColor(new Color(171, 255, 243)); //160,160,230 cellRenderer.setBorderSelectionColor(Color.black); cellRenderer.setTextSelectionColor(Color.white); cellRenderer.setTextNonSelectionColor(Color.blue); node data = null; if (value instanceof DefaultMutableTreeNode) { final DefaultMutableTreeNode node1 = (DefaultMutableTreeNode) value; final Object userObject = node1.getUserObject(); if (userObject instanceof node) { data = (node) userObject; } } if(data!=null) { if(data.isEvaluate()) { setForeground(new Color(0, 105 ,5)); //230,20,30 setFont(new Font("Tahoma", Font.BOLD, 14)); }else { setForeground(new Color(0, 0 ,0)); setFont(new Font("Tahoma", Font.PLAIN, 12)); } } return this; } }