Bonjour
j'essai de réaliser des tables triable, voici ke code que j'utilise :
Bien entendu tous les objets retournés par getValueAt() sont comparable, le code fonctionne parfaitement lorsque la table n'est pas vide (cad getRowCount()>0), mais le problème c'est que lorsque je vide la table et je clique sur une colonne du tableheader j'obtiens l'exception suivante: java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
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 tab = new JTable(); class mymodel extends AbstractTableModel{ private static final long serialVersionUID = 1L; String[] colnames={"N°Officiel","N°Travail","Age Actuel","Date Rappel"}; public int getColumnCount() { return 4; } public int getRowCount() { return bd.rappels_pesee.size(); } public String getColumnName(int co){ return colnames[co]; } public Object getValueAt(int ro, int co) { if(co==0) return bd.rappels_pesee.get(ro).fem.num_off; else if(co==1) return bd.rappels_pesee.get(ro).fem.getnum_trav(); else if(co==2) return bd.rappels_pesee.get(ro).fem.getages(); else return bd.rappels_pesee.get(ro).date_rappel; } public boolean isCellEditable(int ro,int co){ return false; } public void setValueAt(Object ob,int ro,int co){ } public Class<?> getColumnClass(int colonne) { return getValueAt(0,colonne).getClass(); } } tab.setDefaultRenderer(Object.class,new DefaultTableCellRenderer()); tab.setModel(new mymodel()); tab.setRowSorter(new TableRowSorter<TableModel>(tab.getModel()));
y-a-t-il un moyen pour ce debarrasser de ce "bug" ??
merci d'avance
Partager