Bonjour,

j'ai un gros problème que tout le monde a déjà eu mais je n'arrive pas a appliquer les réponses à mon cas. Ca fait 2 jours que je cherche et j'en peut plus, aussi je vous demanderai de pas me crier dessus en me filant des liens.

Voila! J'ai une JTable et un AbstractTableModel composé d'un Object[][] (le code arrive) dans le model j appelle une méthode refresh() qui modifie toutes les données. Seulement les lignes supplementaires ne s'affichent pas et les méthoes fire* me créent des exceptions... Pas non plus de addRow sans vector... Aidez moi!!

JTable:
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
 
class FLocale extends JPanel 
				implements ListSelectionListener,
							ActionListener,
							TableModelListener,
							MouseListener{
    FLocale(){
 
...
		Liste = new JTable(TLocale.getInstance());
		...
		Liste.getSelectionModel().addListSelectionListener(this);
		Liste.getModel().addTableModelListener(this);
		...
		Liste.addMouseListener(this);
                ...
    }
...
 
    public void tableChanged(TableModelEvent e) {
        int row = e.getFirstRow();
        int column = e.getColumn();
 
    	TableModel model = (TableModel)e.getSource();
 
        Object data = model.getValueAt(row, column);
 
        Fichiers.getInstance().renommer(row, (String)data);
 
    }
 
...
}
 
class TLocale extends AbstractTableModel{
 
	private String[] columnNames = {" ",
			"Nom",
            "Taille",
    		"Modification"};
    private Object[][] data;
 
    private static TLocale Instance = null;
 
	static TLocale getInstance(){
 
		if(Instance == null)
			Instance = new TLocale();
 
		return Instance;
 
	}
 
    public TLocale(){
 
    	data = Fichiers.getInstance().getListe();
 
    }
 
    public void refresh(){
 
    	data = Fichiers.getInstance().getListe();
 
 
    }
 
    public int getColumnCount() {
        return columnNames.length;
    }
 
    public int getRowCount() {
        return data.length;
    }
 
    public String getColumnName(int col) {
        return columnNames[col];
    }
 
    public Object getValueAt(int row, int col) {
    	System.out.println(row+" "+col);
        return data[row][col];
    }
 
    public Class<?> getColumnClass(int c) {
 
    	if(c==0) return ImageIcon.class;
        return getValueAt(0, c).getClass();
    }
 
    /*
     * Don't need to implement this method unless your table's
     * editable.
     */
    public boolean isCellEditable(int row, int col) {
        //Note that the data/cell address is constant,
        //no matter where the cell appears onscreen.
        if (col != 1 ) {
            return false;
        } else {
            return true;
        }
    }
 
    /*
     * Don't need to implement this method unless your table's
     * data can change.
     */
    public void setValueAt(Object value, int row, int col) {
        data[row][col] = value;
        fireTableCellUpdated(row, col);
    }
 
}
je vous en prie...

Sinon le plus logique:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
 
     public void refresh(){
 
    	data = Fichiers.getInstance().getListe();
    	fireTableDataChanged();
 
    }
Produit:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
 
Exception in thread "AWT-EventQueue-1" java.lang.ArrayIndexOutOfBoundsException: 0
	at com.hosteur.ui.TLocale.getValueAt(FLocale.java:357)
	at com.hosteur.ui.FLocale.tableChanged(FLocale.java:245)
	at javax.swing.table.AbstractTableModel.fireTableChanged(Unknown Source)
	at javax.swing.table.AbstractTableModel.fireTableDataChanged(Unknown Source)
	at com.hosteur.ui.TLocale.refresh(FLocale.java:339)
...
Y a t'il une erreur dans mon tableChanged?