My class extended from DefaultTableModel

I try:

super.removeRow(...);

And

this.removeRow(...);

Why do they both work?

有帮助吗?

解决方案 2

not an answer, but this.whatever can be pretty misspeled in most complex Swing GUI

super.removeRow(...);

And

this.removeRow(...);

should be (my view to avoid ....)

myTableModel.removeRow() - e.g. ((DefaultTableModel) table.getModel()).removeRow(row);

or you override in XxxTableModel

public void removeRowAt(int row) {

其他提示

super refers to the super (parent) type's implementation.

this refers the the current type's implementation, if one exists, otherwise looks up the inheritance tree, ie. does the same as super.

Depending on how your class extends DefaultTableModel, they might be calling the same method.

Actually they are calling same method i.e. removeRow in parent class for your case.

Only for the case when you decide to override removeRow in your child class then you can make a call to super.removeRow() like this:

@Override
void removeRow() {
   // call parent class's removeRow
   super.removeRow()
   // rest of implementation
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top