Search code examples
javaswingjtableabstracttablemodel

Java JTable set AbstractTableModel in constructor after my code


I have a class that extends JTable, and I want to set it's AbstractTableModel, but the only way I can see how that's possible is by calling the JTable constructor using super.

However, I need to initialize some variables (that hold the table data) before I call the constructor, which seems not to be possible ("call to super must be first statement in constructor"). How can I do that?


Solution

  • You can set the model after constructing the super class (i.e. JTable) by using the method setModel().