Bonjour,

Voici mon probleme : Je souhaite pouvoir ajouter/supprimer des colonnes dynamiquement. Suite a l'ajout d'une colonne et donc la mise a jour des données présente dans mon modele, j'effectue un fireTableDataChanged();. Le visuel ne bouge pas. J'arrive a contourner le probleme avec un fireTableStructureChanged(); mais cela me gene car je perd mes renderers et mes editors.
La modification/ajout/suppression de ligne fonctionne. Le probleme vient de l'ajout de colonnes.

Composant : JTableFiltrable extend JTable
Model : ModelAbstractTable extends AbstractTableModel

Mes données de table sont stockées dans un objet "DataList" extend ArrayList<Vector<String>>
Mes données de colonnes sont stockées dans un objet Vector<String>


Voici une partie du code de mon modele
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
 
....
 
private DataList originalData;
private DataList dataList;
private Vector<String> columnsName;
....
 
 
/************************************************************************************
                ****                            SET and GET Methods                             *******
************************************************************************************/
	public DataList getDataTable() {
        return dataList;
    }
	public DataList getOriginalDataTable() {
        return originalData;
    }
 
/*---------------------------------------------------------------*/
	@Override
	public int getRowCount() {
        return dataList.size();
    }
    @Override
    public int getColumnCount(){
        return columnsName.size();
    }
 
/*---------------------------------------------------------------*/
    public Vector<String> getRow(int lineIndex) {
    	return dataList.get(lineIndex);
    }
    public int getRow(Vector<String> vectorString) {
    	for (int i = 0; i < dataList.size(); i++)
    	{
    		if (dataList.get(i).toString().equalsIgnoreCase(vectorString.toString()))
    			return i;    				
    	}
    	return -1;
    }
 
    public Vector<String> getColumn(int columnIndex){
     	Vector<String> column = new Vector<String>();
    	for (int i = columnIndex ; i<getColumnCount()*getRowCount() ; i = i + getColumnCount())
    		column.addElement(dataList.get(i).elementAt(0));
 
        return column;
    }
 
/*---------------------------------------------------------------*/
    @Override
    public String getColumnName(int columnIndex) {
        String colName = "";
 
        if (columnIndex <= getColumnCount())
            colName = (String)columnsName.elementAt(columnIndex);
 
        System.out.println(colName);
        return colName;
    }
 
    public Vector<String> getColumnsName() {    
        return columnsName;
    }
 
    public void setColumnsName(Vector<String> columnsName) {    
    	this.columnsName = columnsName;
    }
 
    @Override
    public Class<?> getColumnClass(int columnIndex) {    
    	return getValueAt(0, columnIndex).getClass();
    }
 
/*---------------------------------------------------------------*/
    public boolean isEmptyCell() {
        return emptyCellSpoted;
    }
    public void isEmptyCell(boolean validation) {
        emptyCellSpoted = validation;
    }
 
/*---------------------------------------------------------------*/ 
    @Override
    public boolean isCellEditable(int rowIndex, int columnIndex) {
    	if (User.getInstance().userLevel.equalsIgnoreCase(Constants.LEVEL_ADMIN) ||
    			User.getInstance().userLevel.equalsIgnoreCase(Constants.LEVEL_CALCULATOR))
    		return true;
    	else
    		return false;
    }
 
/*---------------------------------------------------------------*/ 
    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        try {
        	dataList.get(rowIndex).elementAt(columnIndex);
        }
        catch (IndexOutOfBoundsException e) {
        	dataList.get(rowIndex).add(columnIndex, "--");
        	emptyCellSpoted = true;
        }
 
        return dataList.get(rowIndex).elementAt(columnIndex);      
    }
    @Override
    public void setValueAt(Object value, int rowIndex, int columnIndex) {
    	dataList.get(rowIndex).setElementAt(value.toString(), columnIndex);
    	fireTableRowsUpdated(rowIndex, rowIndex);
    }
 
/*---------------------------------------------------------------*/ 
    public void removeLine(int rowIndex) {
    	dataList.remove(rowIndex);
      	fireTableRowsDeleted(rowIndex, rowIndex);
    }
 
    public void removeLine(Vector<String> vectorString) {
    	int rowIndex = getRow(vectorString);
    	dataList.remove(vectorString);
      	fireTableRowsDeleted(rowIndex, rowIndex);
    }
 
    public void addLine(Vector<String> lineToAdd) {
    	dataList.add(lineToAdd);
    	this.fireTableRowsInserted(getRowCount()-1, getRowCount()-1);
    }
/*---------------------------------------------------------------*/ 
 
    public void addColumn(String columnToAdd) {
    	columnsName.add(columnToAdd);
 
    	for (int i=0; i<dataList.size(); i++)
	    	dataList.get(i).add("/AddColumn");
 
    	this.fireTableDataChanged();
    }
 
    public void removeColumn(String columnToRemove) {
    	columnsName.remove(columnToRemove);
        for (int i=0; i<dataList.size(); i++)
	    	dataList.get(i).remove(columnIndex);
    }
    public void removeColumn(int columnIndex) {
    	columnsName.remove(columnIndex);
 
    	for (int i=0; i<dataList.size(); i++)
	    	dataList.get(i).remove(columnIndex);
    }
 
    public void renameColumn(int oldColumn, String name) {
    	Vector<String> newColumsName = new Vector<String>();
 
    	for (int i=0; i<columnsName.size(); i++)
    	{
    		if (i == oldColumn)
    			newColumsName.add(name);
    		else
    			newColumsName.add(columnsName.get(i));
    	}
 
    	columnsName.clear();
    	columnsName.addAll(newColumsName);
    }