bonjour
la code ci-dessous, construit un arbre à partir du textField
je voudrais qu'en cliquant sur le bouton il mette à jour l'arbre (text modifié auparavant)

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
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
import java.awt.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Enumeration;
import java.util.List;
import javax.swing.*;
import javax.swing.tree.*;
import javax.swing.event.*;
 
import de.uni_trier.jane.basetypes.Address;
import de.uni_trier.jane.basetypes.SimulationDeviceID;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
 
 
public class SelecTree extends JFrame implements ActionListener{
  public static void main(String[] args) {
 
    hierarchy = new ArrayList();
    hierarchy.add("1");
    hierarchy.add("2");
    hierarchy.add("3");
    hierarchy.add("0");
    hierarchy.add("5");
    hierarchy.add("7");
    hierarchy.add("0");
    hierarchy.add("8");
    hierarchy.add("10");
    hierarchy.add("11");
    hierarchy.add("-1");
    hierarchy.add("-1");
    new SelecTree(hierarchy);
 
  }
 
 
  static List<String> hierarchy;// = Arrays.asList(1,2,3,0,5,7,0,8,10,11,-1,-1,0,6,9,-1);
 
  static JTextField  textField;
 
  static DefaultMutableTreeNode root;
 
  static JTree tree;
 
  static JScrollPane pane;
 
  static Container content;
 
  public SelecTree(List hierarchy) {
    super("hierarchy parser");
    this.hierarchy=hierarchy;
    content = getContentPane();
 
    root = processHierarchy(this.hierarchy);
    tree = new JTree(root);
    for (int i=0;i<tree.getRowCount();i++)
        tree.expandRow(i);
    //pane= new JScrollPane(tree);
    content.add(tree, BorderLayout.CENTER);
    textField =new JTextField();
    String s=Arrays.toString((Object[])(hierarchy.toArray()));
    s.replaceAll(" ", "");
    textField.setText(s.substring(1,s.length()-1));
    content.add(textField, BorderLayout.NORTH);
    JButton b = new JButton("ok") ;
    content.add(b, BorderLayout.AFTER_LINE_ENDS);
    b.addActionListener(this);
 
 
    setSize(250, 275);
    setVisible(true);
  }
 
int index=0;
 
  private DefaultMutableTreeNode processHierarchy(List hierarchy) {
    this.hierarchy=hierarchy;
    DefaultMutableTreeNode node =
      new DefaultMutableTreeNode(hierarchy.get(index));
    DefaultMutableTreeNode child=null;
    index++;
    while(index <this.hierarchy.size()-1 && Integer.parseInt(this.hierarchy.get(index).replaceAll(" ", ""))!=-1) {
      int a = Integer.parseInt(this.hierarchy.get(index).replaceAll(" ", ""));
      if (a == 0){  //  node with children
        index++;
        child = processHierarchy(this.hierarchy);
      }else{
        child = new DefaultMutableTreeNode(a); //  Leaf
      }
      node.add(child);
      index++;
    }
    return(node);
  }
 
    @Override
    public void actionPerformed(ActionEvent e) {
                textField.setText("2,3");
            String s=textField.getText();
            System.out.println(s);
            String[] t=s.split(",");
            List<String> l=Arrays.asList(t);
            System.out.println(l);
            index =0;
            tree.setEditable(true);
            System.out.println(tree.isEditable());
            root = processHierarchy(l);
            tree = new JTree(root);
            for (int i=0;i<tree.getRowCount();i++)
                tree.expandRow(i);
            tree.updateUI();
System.out.println(tree.getModel().getRoot());
System.out.println(((DefaultMutableTreeNode) tree.getModel().getRoot()).getDepth());
System.out.println(root);
System.out.println(root.getDepth());
            //pane= new JScrollPane(tree);
        this.validate();
        this.repaint();
    }
 
 
}
je voudrais remplacer l'ancien Tree par le nouveau

dans le code, le bouton change l'arbre, on le voit par les system.out, le root devient 2, mais ça ne change pas sur la Jframe, je ne sais pas comment