質問

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