代码首先声明了一个接口变量columnModel,然后没定义就直接使用它的方法了。
找到赋值的地方了,原来在没有用带TableModel参数或该参数为null的JTable构造器时,
构造器里有一段代码为JTable实例设定默认的TableModel:
public JTable(TableModel dm, TableColumnModel cm, ListSelectionModel sm) { super(); setLayout(null); //...省略部分代码 // Set the model last, that way if the autoCreatColumnsFromModel has // been set above, we will automatically populate an empty columnModel // with suitable columns for the new model. if (dm == null) { dm = createDefaultDataModel(); } setModel(dm); initializeLocalVars(); updateUI(); }