Assing diferentes iconos a diferentes nodos en un JTree

Is it possible to assign different icons to different nodes in a JTree usar DefaultTreeCellRenderer.setOpenIcon()? Gracias.

preguntado el 27 de agosto de 11 a las 16:08

1 Respuestas

The same cell renderer instance is used to render all the cells of the tree. The open icon is the little + symbol, or triangle symbol at the left of every tree node which allows to expand it (i.e. see its child nodes). I doubt this is the icon you want to change. It would be rather strange not to use the same one for all the nodes.

If you want to display a custom icon for a specific node, create a subclass of DefaultTreeCellRenderer, override the getTreeCellRendererComponent method, decide which icon to display based on the value passed to the method, and call setIcon.

Vea http://download.oracle.com/javase/tutorial/uiswing/components/tree.html#display for a similar example (which customized the tooltip, and not the icon, but the idea is the same).

Respondido 27 ago 11, 20:08

Véase también TreeIcon. - basurero

Thank you both JB Nizet and trashgod - FadelMS

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.