Criei uma árvore com o jtree, mas não estou conseguindo selecionar um nodo automaticamente ao ler a base de dados, até agora o melhor que consegui foi isso:
[code]
public void selecionaNodo( JTree tree, String pNomeFuncao ) {
TreePath lPath = tree.getPathForRow(1);
if( lPath.getPathComponent(1) instanceof DefaultMutableTreeNode) {
DefaultMutableTreeNode lNode = (DefaultMutableTreeNode) lPath.getPathComponent(1);
selecionaNodo( lNode, pNomeFuncao );
}
}
public TreeNode[] selecionaNodo( DefaultMutableTreeNode lNode, String pNomeFuncao ) {
for( int i=0; i<lNode.getChildCount(); i++ ) {
Object lFolha = lNode.getChildAt(i);
if( lFolha.toString().equals( pNomeFuncao ) ) {
//TreeNode root = (TreeNode) this.getModel().getRoot();
}
if( lFolha instanceof DefaultMutableTreeNode ) {
DefaultMutableTreeNode folha = (DefaultMutableTreeNode) lFolha;
selecionaNodo( folha, pNomeFuncao );
}
}
return null;
}[/code]
Obrigado a todos