It is relaed to the thread i posted a while ago. Before I edited the model of my table, it was working properly, but when i added some columns thats when the problem came out. Everytime i click the button that will open this window, it goes blank. Only a big window filled with white comes out.
here is my code:
tblInventory.setModel(new TableDefault(
new Object[][] {
},
new String[] {
"Borrow", "ItemID", "Item Description", "Quantity", "In-Stock", "Out-Stock", "Last Borrowed", "Remarks"
},
new Class[]{String.class, Boolean.class}
));
System.out.println("lllllllll");
scrollPane.setViewportView(tblInventory);
JButton btnOk = new JButton("Ok");
btnOk.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
System.out.println("Doradora: "+booboo);
}
});
btnOk.setBounds(786, 680, 89, 23);
inventoryframe.getContentPane().add(btnOk);
System.out.println("ccccccccccc");
checkbox = new JCheckBox("borrow");
checkbox.setHorizontalAlignment(SwingConstants.CENTER);
checkbox.setBounds(360, 63, 97, 23);
TableColumn borrow = tblInventory.getColumnModel().getColumn(0);
borrow.setCellEditor(new DefaultCellEditor(checkbox));
doIt();
}
public void doIt(){
TableDefault dtm = (TableDefault) tblInventory.getModel();
dtm.getDataVector().removeAllElements();
NewAndtemTableSelectionImpl myReader = new NewAndtemTableSelectionImpl();
List<Item> newItemList = myReader.showAllItems();
for (Item myNewItems : newItemList) {
Object[] rowData = new Object[8];
rowData[1] =myNewItems.getItemID();
rowData[2] =myNewItems.getItemDes();
rowData[3] =myNewItems.getQuantity();
rowData[4] =myNewItems.getInstock();
rowData[5] =myNewItems.getOutstock();
rowData[6] =myNewItems.getDateReturn();
rowData[7] =myNewItems.getRemarks();
dtm.addRow(rowData);
}
tblInventory.updateUI();
}
}
and it goes with this exception:
Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Boolean
this is the other class:
package app.util;
import javax.swing.table.DefaultTableModel;
public class TableDefault extends DefaultTableModel{
private Class[] columnTypes;
public TableDefault(Object[][] data, Object[] columnNames,
Class[] columnTypes) {
super(data, columnNames);
this.columnTypes = columnTypes;
}
@Override
public Class<?> getColumnClass(int columnIndex) {
return columnTypes[columnIndex];
}
}