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());

[4323 byte] By [Maaartena] at [2007-11-27 4:51:28]
# 1
Use the DefaultTableModel. Then you use the constructor that accepts the column names and row count (which you set to 0). Then you use the addRow(...) method to add rows to the model.
camickra at 2007-7-12 10:05:12 > top of Java-index,Desktop,Core GUI APIs...
# 2
Yeah, that's a possible option but if you use de defaulttableModel all data is formatted as String. But I want, for example, a checkbox for a boolean. But maybe you can also reach that result with a columnmodel?Thanks for the help anyway
Maaartena at 2007-7-12 10:05:12 > top of Java-index,Desktop,Core GUI APIs...
# 3
> but if you use de defaulttableModel all data is formatted as StringSo you override the getColumnClass() method to provide the Class of each column.
camickra at 2007-7-12 10:05:12 > top of Java-index,Desktop,Core GUI APIs...