JTree implementation TreeCellRenderer
Bonjour,
je tente de mettre un logo spécifique sur certain noeud de mon arbre :
j'ai donc implementer TreeCellRenderer lors de la création de mes noeuds j'ai un null pointeur exception :oops: car mon constructeur est vide
le code de mon TreeCellRenderer
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
|
public class MethodeCellRenderer implements TreeCellRenderer {
DefaultTreeCellRenderer defaultRenderer = new DefaultTreeCellRenderer();
static String path = "../icones/";
static Icon[] icoMethode = {
new ImageIcon(path + "ico_function.ico"),
new ImageIcon(path + "ico_procedure.ico")};
/** Creates a new instance of MethodeCellRenderer */
public MethodeCellRenderer() {
//je vois pas ce que j'ai a y mettre :oops:
}
public Component getTreeCellRendererComponent(JTree tree, Object value,
boolean selected, boolean expanded, boolean leaf, int row,
boolean hasFocus) {
Component returnValue = null;
if ((value != null) && (value instanceof DefaultMutableTreeNode)) {
Object userObject = ((DefaultMutableTreeNode) value)
.getUserObject();
if (userObject instanceof Fonction) {
Fonction fonction = (Fonction) userObject;
defaultRenderer.setOpenIcon(this.icoMethode[0]);
} else {
defaultRenderer.setOpenIcon(this.icoMethode[1]);
}
}
return defaultRenderer.getTreeCellRendererComponent(tree,
value, selected, expanded, leaf, row, hasFocus);
}
} |
Voici comment je l'appelle lors de la construction des noeuds :
Code:
1 2 3 4 5 6 7 8 9
|
public void createNodes(DefaultMutableTreeNode category, Methode laMethode){
for(int j=0; j<laMethode.getNbMethode(); j++){
Methode laSousMethode = (Methode)laMethode.getSousMethode(j);
(laSousMethode.getNomMethode());
TreeCellRenderer renderer = new MethodeCellRenderer();
this.tree.setCellRenderer(renderer);
... |
Merci de votre aide