JTable does'nt add first row when data was set null by construction
Hey,
I'm making an application to manage stocks. I use a table to show details of stocks. This table is filled with information from a server. My problem: when you have no stocks the setData() method from the overrided datamodel gets a null. When you later on add a stock. I wanted to show the details in the table. But he doesn't show it. On the other side. When there is allready a record in the database on the server. He show it in the table when you open the program and when you then add a stock it is without problem added to table. Frustrating problem, who can help?
Some code:
The tablemodel
publicclass StockDetailsTableModelextends AbstractTableModel{
Object[][] data =null;
Class[] columnClasses;
String[] columnNames;
/** Creates a new instance of StockDetailsTableModel */
public StockDetailsTableModel(Class[] columnClasses, Object[][] data, String[] columnNames){
this.columnClasses = columnClasses;
this.data = data;
this.columnNames = columnNames;
}
public Class getColumnClass(int col){
return columnClasses[col];
}
public Object getValueAt(int row,int col){
return data[row][col];
}
publicint getColumnCount(){
int cols = 0;
try{
cols= data[0].length;
}catch(Exception e){}
return cols;
}
publicint getRowCount(){
int rows = 0;
try{
rows = data.length;
}catch(Exception e){}
return rows;
}
public String getColumnName(int col){
return columnNames[col];
}
publicvoid setData(Object[][] data){
this.data = data;
this.fireTableDataChanged();
}
}
the code in the constructor of the panel where I use the table
tblSubStocks =new javax.swing.JTable(new StockDetailsTableModel(stock.getStockColumnIdentifiers(), stock.getStockDetails(), stock.getStockColumnNames()));
selectedRow = 0;
model = (StockDetailsTableModel) tblSubStocks.getModel();
model.setData(stock.getStockDetails());
the code for updating the data in the table
publicvoid updateData(){
try{
lsm.removeListSelectionListener(stockDetailSelectListener);
model.setData(stock.getStockDetails());
if (tblSubStocks.getRowCount() > 0){
tblSubStocks.setRowSelectionInterval(stock.getDetailIndex(), stock.getDetailIndex());

