I have a JTable
with a custom TableModel
called DataTableModel
. I initialized the table with a set of column names and no data as follows:
books = new JTable(new DataTableModel(new Vector<Vector<String>>(), title2));
JScrollPane scroll1 = new JScrollPane(books);
scroll1.setEnabled(true);
scroll1.setVisible(true);
JSplitPane jsp1 = new JSplitPane(JSplitPane.VERTICAL_SPLIT, scroll1, scroll2);
JSplitPane jsp2 = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, inventory, jsp1);
myPanel.add(jsp2, BorderLayout.CENTER);
I later want to update books with a set of data, and use the following:
DataTableModel d = (DataTableModel)books.getModel();
d.setValues(bookList);
books.setModel(d);
where bookList is a Vector<Vector<String>>
that definitely has data. However, although all this code is being executed, it is not displaying on the screen. The code for the setValues()
method is:
public void setValues(Vector<Vector<String>> v) {
values = v;
fireTableDataChanged();
}
Am I missing something here?
The class and methods for my DataTableModel are (these methods are all implemented to return correct results):
public class DataTableModel extends AbstractTableModel {
public DataTableModel(Vector<Vector<String>> v, Vector<String> c) {}
public int getColumnCount() {
if (values != null && values.size() > 0)
return values.elementAt(0).size();
else
return 0;
}
public int getRowCount() {
if (values != null && values.size() > 0)
return values.size();
else
return 0;
}
public Object getValueAt(int arg0, int arg1) {}
public void setValues(Vector<Vector<String>> v) {}
public Vector<Vector<String>> getValues() {}
public void setColumnNames(Vector<String> columns) {}
public String getColumnName(int col) {}
}