I initialized a column name in a method and added a column name
New Vector (); Columnnames.add ("School Number"); Columnnames.add ("name"); Columnnames.add ("gender"); Columnnames.add ("age"); Columnnames.add ("birthplace"); Columnnames.add ("department");
Because you need to display column names in JTable, you need to override the getColumnName method in Abstracttablemodel.
@Override Public String getColumnName (int column) { //return (String) this.columnNames.get (column ); return This . getColumnName (column); }
Run, Error:Exception in thread "main" Java.lang.StackOverflowError
It's embarrassing. First, I guess it might be a way to get the length of a column getcolumncount problem.
@Override Public int getColumnCount () { returnthis. Columnnames.size (); }
But on the console output, the result is equal to 6. Well, that's not the problem. Look for a question after the return statement.
First enter this in the getColumnName method, followed by return.
Look at the tool to give me the hint, found that there are columnnames, choose this again "." I found a GET method, it needs to pass a parameter, just int, so I have a bold idea.
@Override Public String getcolumnname (int column) { returnthis. Columnnames.get (column); }
OK, write well, run a bit, the name of the list is not defective display.
Very happy, solve the problem, by the way to write this article, the Java small white to record my problem-solving ideas.
Rewrite getColumnName () method Error Java.lang.StackOverflowError