org.jdesktop.swingbinding.JTableBinding$BindingTableModel cannot be cast to javax.swing.table.DefaultTableModel

后端 未结 2 1575
野性不改
野性不改 2021-01-24 09:00

I tried to group JTable header and for that I want to get the DefaultTableModel of current JTable. But when I tried to retrieve the table model like this:

Defaul         


        
2条回答
  •  渐次进展
    2021-01-24 09:25

    you have to create your table like this :

        String[] columnNames = {"Row",
                "Category",
                "From Date",
                "From Time",
                "To Date",
                "To Time",
                "Description",
                "Doc"};
        Object[][] data = {};//Table Rows
    
       table.setModel(new DefaultTableModel(data,columnNames));
    

    instead of:

       table=new JTable(data,columnNames);
    

    then you can cast your table model to defaultTableModel.

提交回复
热议问题