Pessoal, eu sei que esse assunto ja esta chato, mas estou com um problemao com a JTree aqui…
link de um artigo
http://www.guj.com.br/posts/list/37821.java
ta rodando beleza, acrescentando os valores, mas com apenas um problema… ele nao atualiza quando chamo o método novamente…
void carregaPendencias() {
try {
String query = "";
String subQuery = "";
if (jCheckBox1.isSelected()) {
subQuery = " TP_ENCARREGADO = '" + GeomapView.codigoUsuario + "' and ";
}
List<Projetos> projetos = new ArrayList<Projetos>();
Projetos projeto;
ResultSet rs1;
Statement stmt1 = conn.createStatement();
rs = stmt.executeQuery("SELECT TC_NOME, TC_RAZAO_SOCIAL from tab_projetos, tab_fazendas, tab_grupo_imoveis, tab_clientes WHERE " + subQuery + " TP_CODIGO = TGI_TP_CODIGO and TC_CODIGO = TP_CODIGO_CLIENTE and TF_CODIGO = TGI_TC_CODIGO and TP_VISIVEL = 1 and TF_VISIVEL=1 and TC_VISIVEL = 1 GROUP BY TC_NOME, TC_RAZAO_SOCIAL");
rs.last();
rs.beforeFirst();
int x = 0;
while (rs.next()) {
if (rs.getString(1) == null | rs.getString(1).equals("")) {
projeto = new Projetos(rs.getString(2));
} else {
projeto = new Projetos(rs.getString(1));
}
rs1 = stmt1.executeQuery("SELECT * FROM tab_fazendas, tab_grupo_imoveis, tab_projetos WHERE " + subQuery + " TF_CODIGO_CLIENTE = '" + utils.pegaCliente(rs.getString(1)) + "' and TGI_TC_CODIGO = TF_CODIGO and TP_CODIGO = TGI_TP_CODIGO and TP_VISIVEL = 1 and TF_VISIVEL = 1 GROUP BY TF_NOME");
while (rs1.next()) {
projeto.addFazenda(new Fazendas(rs1.getString("TF_NOME"), rs1.getInt("TF_CODIGO")));
}
projetos.add(projeto);
x++;
}
modelo = new ProjetoTreeModel(projetos);
arvoreProjetos = new JTree(modelo);
arvoreProjetos.setRootVisible(false);
modelo.addTreeModelListener(new TreeModelListener() {
public void treeNodesChanged(TreeModelEvent e) {
DefaultMutableTreeNode node;
System.out.println(e.getPath().toString());
System.out.println("The user has finished editing the node.");
//System.out.println("New value: " + node.getUserObject());
}
public void treeNodesInserted(TreeModelEvent e) {
}
public void treeNodesRemoved(TreeModelEvent e) {
}
public void treeStructureChanged(TreeModelEvent e) {
}
});
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
O que devo fazer para que minha tree funcione corretamente? a parte de pesquisa parece estar ok, pois na primeira chamada ao método ela é preenchida corretamente!
Outra coisa, como posso adicionar um listener para escutar os comandos de mouse e teclado?
Agradeço muito! :-o
Obrigado