hi
i'm using this class as a model for my JTable:
i use setModel to update my JTable... but it only works if the table is not empty.PHP Code:
import java.awt.Dimension;
import java.sql.Date;
import java.util.ArrayList;
import javax.swing.JFrame;
import javax.swing.JTable;
import javax.swing.table.AbstractTableModel;
import GUI.Statiques;
public class TabPresenceModelFiltre extends AbstractTableModel
{
Date dateMax;
Date dateMin;
String shift;
private ArrayList<FichePresence> data;
private String[] names = { "Date", "Shift", "Op présent", "Op absent", "Op arrêté" };
public TabPresenceModelFiltre(Date dateMax, Date dateMin, String shift)
{
super();
this.dateMax = dateMax;
this.dateMin = dateMin;
this.shift = shift;
data = FichePresence.getFiles(dateMin, dateMax, shift);
}
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;
}
}
in other words i can update the table it's not empty, but i get IndexOutOfBoundsException if my table is empty.
thank you