I am trying to add data read in from a form into a jTable. So far this is what I have and Im not sure why it will not work. This is the code:
public void fillTable(){
String inputField1 = jTextArea1.getText();
String inputField2 = jTextField8.getText();
String inputField3 = jComboBox1.getSelectedItem().toString();
String inputField4 = jTextField11.getText();
DefaultTableModel model = (DefaultTableModel) jTable2.getModel();
int numRows = jTable2.getRowCount();
for (int i = 0; i <= numRows; i++){
model.setValueAt(inputField1, numRows, 1);
model.setValueAt(inputField2, numRows, 2);
model.setValueAt(inputField3, numRows, 4);
model.setValueAt(inputField4, numRows, 6);
}
jTable2.setModel(model);
}
The error I get is:
Exception in thread "AWT-EventQueue=0" java.lang.ClassCastException: my.rcs.accounting.DraftInvoice$5 cannot be cast to groovy.model.DefaultTableModel
What am I doing wrong and how can I fix this?
Thank you!
numRows(which will throw an exception BTW).jTable2.getModelreturn amy.rcs.accounting.DraftInvoiceand not agroovy.model.DefaultTableModelwhich result in an exception when you try to castDefaultTableModel model = (DefaultTableModel) jTable2.getModel();. You should try to useDraftInvoice model = (DraftInvoice ) jTable2.getModel().