Problème de définition de constructeur pour TableModel
bonjour,
j'ai une classe qui me sert de TableModel pour mon JTable, et ca fonctionne sans problème:
Code:
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
| public class TabPresenceModelTout extends AbstractTableModel
{
private String[] names = { "Date", "Shift", "Op présent", "Op absent",
"Op arrêté" };
private ArrayList<FichePresence> data = FichePresence
.recupererFichePresence();
public String getColumnName(int col)
{
return names[col];
}
public int getRowCount()
{
return data.size();
}
public int getColumnCount()
{
return names.length;
}
public Class getColumnClass(int c)
{
try
{
switch (c)
{
case 0:
return Class.forName("Date");
case 1:
return Class.forName("String");
case 2:
return Class.forName("Integer");
case 3:
return Class.forName("Integer");
case 4:
return Class.forName("Integer");
default:
return null; // Ne devrait jamais arriver
}
} catch (ClassNotFoundException e)
{
return getValueAt(0, c).getClass();
}
}
public Object getValueAt(int rowIndex, int columnIndex)
{
switch (columnIndex)
{
case 0:
return data.get(rowIndex).getDate();
case 1:
return data.get(rowIndex).getposte();
case 2:
return data.get(rowIndex).getNbrPresent();
case 3:
return data.get(rowIndex).getNbrAbsent();
case 4:
return data.get(rowIndex).getNbrArrete();
default:
return null; // Ne devrait jamais arriver
}
}
public boolean isCellEditable(int row, int col)
{
return false;
}
} |
l'idée est d'ajouter un constructeur (avec des paramètres) a cette classe pour que ce dernier crée le data du model en fonction de ces paramètres:
Code:
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
| public class TabPresenceModelFiltre extends AbstractTableModel
{
Date dateMax;
Date dateMin;
String shift;
private ArrayList<FichePresence> data;
public TabPresenceModelFiltre(Date dateMax, Date dateMin, String shift)
{
super();
this.dateMax = dateMax;
this.dateMin = dateMin;
this.shift = shift;
ArrayList<FichePresence> data = FichePresence.recupererFichePresence(
dateMin, dateMax, shift);
}
private String[] names = { "Date", "Shift", "Op présent", "Op absent",
"Op arrêté" };
public String getColumnName(int col)
{
return names[col];
}
public int getRowCount()
{
return data.size();
}
public int getColumnCount()
{
return names.length;
}
public Class getColumnClass(int c)
{
try
{
switch (c)
{
case 0:
return Class.forName("Date");
case 1:
return Class.forName("String");
case 2:
return Class.forName("Integer");
case 3:
return Class.forName("Integer");
case 4:
return Class.forName("Integer");
default:
return null; // Ne devrait jamais arriver
}
} catch (ClassNotFoundException e)
{
return getValueAt(0, c).getClass();
}
}
public Object getValueAt(int rowIndex, int columnIndex)
{
switch (columnIndex)
{
case 0:
return data.get(rowIndex).getDate();
case 1:
return data.get(rowIndex).getposte();
case 2:
return data.get(rowIndex).getNbrPresent();
case 3:
return data.get(rowIndex).getNbrAbsent();
case 4:
return data.get(rowIndex).getNbrArrete();
default:
return null; // Ne devrait jamais arriver
}
}
public boolean isCellEditable(int row, int col)
{
return false;
}
} |
ça marche pas et ça donne une erreur de type NullPointerException à la ligne:
Code:
return data.size();
merci pour votre aide :zoubi: