[Problema] - Listener JTree

1 resposta
F

Como posso adicionar um listener para saber quando um nodo é selecionado numa JTree ? ja tentei adicionar TreeSelectionListener e implementar o metodo valueChange mas nao deu certo.

1 Resposta

lina

Oi,

Você está no caminho certo! Ou seja, você deve usar um TreeSelectionListener.

Segue:

// Coloque isso dentro do método valueChanged do TreeSelectionListener.
final TreePath lo_path	= e.getNewLeadSelectionPath();

if (lo_path != null) {
      
      // Recebe a seleção do nodo ...
     Object	lo_selection = ((DefaultMutableTreeNode)lo_path.getPathComponent(lo_path.getPathCount()-1)).getUserObject();
}

Tchauzin!

Criado 16 de novembro de 2009
Ultima resposta 18 de nov. de 2009
Respostas 1
Participantes 2