问题描述
我尝试对JTable标头进行分组,为此我想获得当前JTable的DefaultTableModel。但是当我试图像这样检索表模型时:
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:
DefaultTableModel dm=(DefaultTableModel) tblTet.getModel();
它显示以下异常:
因为我使用的是JTableBeansBinding。
Because I am using JTableBeansBinding.
有谁知道如何解决这个问题(检索DefaultTableModel)?
Does anyone know how to solve this problem (for retrieving DefaultTableModel)?
推荐答案
根据,该类不扩展DefaultTableModel。相反,它实现了TableModel接口。这意味着你不能转换为DefaultTableModel,只能转换为TableModel:
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();
这篇关于org.jdesktop.swingbinding.JTableBinding $ BindingTableModel无法强制转换为javax.swing.table.DefaultTableModel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!