consegui (ufa), o problema eh q eu tava definindo:
setClosedIcon();
setOpenIcon();
setLeafIcon();
enqto no renderer vc soh deve definir:
setIcon();
vo manda o exemplo completo pra quem quizer:
[code]import java.awt.;
import java.awt.event.;
import javax.swing.;
import javax.swing.tree.;
public class TreeEditTest extends JFrame implements ActionListener {
private DefaultTreeModel model;
private JTree tree;
private JButton addSiblingButton, addChildButton, deleteButton, editButton;
public TreeEditTest() {
setTitle("TreeEditTest");
setSize(300, 200);
setDefaultCloseOperation(EXIT_ON_CLOSE);
TreeNode root = makeSampleTree();
model = new DefaultTreeModel(root);
tree = new JTree(model);
tree.setEditable(true);
tree.setCellRenderer(new RenderizarTree());
Container contentPane = getContentPane();
JScrollPane scrollPane = new JScrollPane(tree);
contentPane.add(scrollPane, "Center");
JPanel panel = new JPanel();
addSiblingButton = new JButton("Add Sibling");
addSiblingButton.addActionListener(this);
panel.add(addSiblingButton);
addChildButton = new JButton("Add Child");
addChildButton.addActionListener(this);
panel.add(addChildButton);
deleteButton = new JButton("Delete");
deleteButton.addActionListener(this);
panel.add(deleteButton);
contentPane.add(panel, "South");
}
public TreeNode makeSampleTree() {
DefaultMutableTreeNode root = new DefaultMutableTreeNode("World");
DefaultMutableTreeNode contry = new DefaultMutableTreeNode("USA");
root.add(contry);
DefaultMutableTreeNode state = new DefaultMutableTreeNode("California");
contry.add(state);
DefaultMutableTreeNode city = new DefaultMutableTreeNode("San Jose");
state.add(city);
city = new DefaultMutableTreeNode("Cupertino");
state.add(city);
state = new DefaultMutableTreeNode("Michigan");
contry.add(state);
city = new DefaultMutableTreeNode("Ann Arbor");
state.add(city);
contry = new DefaultMutableTreeNode("Germany");
root.add(contry);
state = new DefaultMutableTreeNode("Schleswig-Holstein");
contry.add(state);
city = new DefaultMutableTreeNode("Kiel");
state.add(city);
return root;
}
public void actionPerformed(ActionEvent evt) {
DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent();
if(selectedNode == null)
return;
if(evt.getSource().equals(deleteButton)) {
if(selectedNode.getParent() != null)
model.removeNodeFromParent(selectedNode);
return;
}
DefaultMutableTreeNode newNode = new DefaultMutableTreeNode("New");
if(evt.getSource().equals(addSiblingButton)) {
DefaultMutableTreeNode parent = (DefaultMutableTreeNode) selectedNode.getParent();
if(parent != null) {
int selectedIndex = parent.getIndex(selectedNode);
model.insertNodeInto(newNode, parent, selectedIndex + 1);
}
} else if(evt.getSource().equals(addChildButton)) {
model.insertNodeInto(newNode, selectedNode, selectedNode.getChildCount());
}
TreeNode[] nodes = model.getPathToRoot(newNode);
TreePath path = new TreePath(nodes);
tree.scrollPathToVisible(path);
}
public static void main(String[] args) {
new TreeEditTest().setVisible(true);
}
}
class RenderizarTree extends DefaultTreeCellRenderer implements TreeCellRenderer {
private Font plainFont, italicFont;
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
super.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus);
DefaultMutableTreeNode node = (DefaultMutableTreeNode) value;
if(node.toString().equals("USA")) {
setIcon(new ImageIcon("iconTest.gif"));
}
return this;
}
}[/code]