Exception in thread “AWT-EventQueue-0” java.lang.ClassCastException: javax.swing.JTable

后端 未结 2 733
温柔的废话
温柔的废话 2020-12-22 02:51

I have a code which when run generates a table in swing form which contains a set of checkboxes which can be selected or unselected

When I click on the Check All ta

相关标签:
2条回答
  • 2020-12-22 03:28

    You are casting the source of the event to a JTableHeader:

    JTableHeader header = (JTableHeader) (e.getSource());
    

    and the source is a JTable when you click at a cell. I would have two different listeners for the header and the cell selection or you can do a hack by checking event.getSource() instanceof ... in your mouse-click-listener.

    0 讨论(0)
  • 2020-12-22 03:33

    On line 152: JTableHeader header = (JTableHeader)(e.getSource()); you are assuming the event is on the table header. You need to check event source's class to see if it's on the header or an individual checkbox.

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