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];
    }
}

Edited 2 Years Ago by wallet123

oh sorry, this is the whole exception:

Exception in thread "AWT-EventQueue-0" java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Boolean
    at javax.swing.JTable$BooleanRenderer.getTableCellRendererComponent(Unknown Source)
    at javax.swing.JTable.prepareRenderer(Unknown Source)
    at javax.swing.plaf.basic.BasicTableUI.paintCell(Unknown Source)
    at javax.swing.plaf.basic.BasicTableUI.paintCells(Unknown Source)
    at javax.swing.plaf.basic.BasicTableUI.paint(Unknown Source)
    at javax.swing.plaf.ComponentUI.update(Unknown Source)
    at javax.swing.JComponent.paintComponent(Unknown Source)
    at javax.swing.JComponent.paint(Unknown Source)
    at javax.swing.JComponent.paintChildren(Unknown Source)
    at javax.swing.JComponent.paint(Unknown Source)
    at javax.swing.JViewport.paint(Unknown Source)
    at javax.swing.JComponent.paintChildren(Unknown Source)
    at javax.swing.JComponent.paint(Unknown Source)
    at javax.swing.JComponent.paintChildren(Unknown Source)
    at javax.swing.JComponent.paint(Unknown Source)
    at javax.swing.JComponent.paintChildren(Unknown Source)
    at javax.swing.JComponent.paint(Unknown Source)
    at javax.swing.JLayeredPane.paint(Unknown Source)
    at javax.swing.JComponent.paintChildren(Unknown Source)
    at javax.swing.JComponent.paintToOffscreen(Unknown Source)
    at javax.swing.RepaintManager$PaintManager.paintDoubleBuffered(Unknown Source)
    at javax.swing.RepaintManager$PaintManager.paint(Unknown Source)
    at javax.swing.RepaintManager.paint(Unknown Source)
    at javax.swing.JComponent.paint(Unknown Source)
    at java.awt.GraphicsCallback$PaintCallback.run(Unknown Source)
    at sun.awt.SunGraphicsCallback.runOneComponent(Unknown Source)
    at sun.awt.SunGraphicsCallback.runComponents(Unknown Source)
    at java.awt.Container.paint(Unknown Source)
    at java.awt.Window.paint(Unknown Source)
    at javax.swing.RepaintManager$3.run(Unknown Source)
    at javax.swing.RepaintManager$3.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
    at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
    at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source)
    at javax.swing.RepaintManager.prePaintDirtyRegions(Unknown Source)
    at javax.swing.RepaintManager.access$1100(Unknown Source)
    at javax.swing.RepaintManager$ProcessingRunnable.run(Unknown Source)
    at java.awt.event.InvocationEvent.dispatch(Unknown Source)
    at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
    at java.awt.EventQueue.access$200(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)

it did not specify which line exactly, but as i go through it , I figured that the window goes blank when it pass throught line number 46, where i start to add data.

ive checked my code, and i think it still looked exactly as you instructed me a while ago ...
but here, i tried to modify it.:

        TableColumn Borrow = tblInventory.getColumnModel().getColumn(7);
        Borrow.setCellEditor(new DefaultCellEditor(checkbox));


            doIt();

    }

    public void doIt(){

        DefaultTableModel dtm = (DefaultTableModel) tblInventory.getModel();
        dtm.getDataVector().removeAllElements();

        NewAndtemTableSelectionImpl myReader = new NewAndtemTableSelectionImpl();

        List<Item> newAllItemList = myReader.showAllItems();
        for (Item myAllItems : newAllItemList) {
            Object[] rowData = new Object[7];
            rowData[0] =myAllItems.getItemID();
            rowData[1] =myAllItems.getItemDes();
            rowData[2] =myAllItems.getQuantity();
            rowData[3] =myAllItems.getInstock();
            rowData[4] =myAllItems.getOutstock();
            rowData[5] =myAllItems.getDateReturn();
            rowData[6] =myAllItems.getRemarks();

            dtm.addRow(rowData);
        }
        tblInventory.updateUI();
    }


}

Edited 2 Years Ago by wallet123

This question has already been answered. Start a new discussion instead.