Bonsoir,
J'ai crée une arborescence (jtree), maintenant je veux afficher les informations de chaque noeud séparément dans un jtextarea à partir d'un fichier xml, ensuite apporter des modifications au contenu et le sauvegarder. Est ce que c'est réalisable? ou bien j'utilise une base de données??
pour l'instant j'ai pu que afficher les noms des noeuds dans un jtextarea l'une après l'autre lors de chaque clic.
Voici le bout de code:
Merci pour vos suggestions.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 //Where the tree is initialized: tree.getSelectionModel().setSelectionMode (TreeSelectionModel.SINGLE_TREE_SELECTION); //Listen for when the selection changes. tree.addTreeSelectionListener(new TreeSelectionListener() { public void valueChanged(TreeSelectionEvent e) { //Returns the last path element of the selection. //This method is useful only when the selection model allows a single selection. DefaultMutableTreeNode node = (DefaultMutableTreeNode) tree.getLastSelectedPathComponent(); if (node == null) //Nothing is selected. return; Object nodeInfo = node.getUserObject(); if (nodeInfo instanceof String) jTextarea.append((String)nodeInfo+"\n\r"); }});
Partager