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

后端 未结 2 1552
野性不改
野性不改 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:20

    According to the JavaDoc for BindingTableModel, the class doesn't extend DefaultTableModel. Rather, it implements TableModel interface. This means that you cannot cast to DefaultTableModel, only to TableModel:

    TableModel dm=(TableModel) tblTet.getModel();
    
    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题