左右默认有数字,按照从小到大的顺序往下排。
Java Swing jtable 行业数据
------解决方案--------------------
一个简单的静态代理hack:
import javax.swing.JTable;
import javax.swing.event.TableModelListener;
import javax.swing.table.TableModel;
public class LineNumber {
public static void decorate(JTable table) {
if( table == null )
throw new NullPointerException("table is null.");
TableModel model = table.getModel();
if( !(model instanceof LineNumberTableModel) )
table.setModel(new LineNumberTableModel(model));
}
private static class LineNumberTableModel implements TableModel {
private final TableModel model;
private LineNumberTableModel(TableModel model) {
this.model = model;
}
@Override
public int getRowCount() {
return model.getRowCount();
}
@Override
public int getColumnCount() {
return 1 + model.getColumnCount();
}
@Override
public String getColumnName(int columnIndex) {
return columnIndex == 0 ? "Row" : model.getColumnName(columnIndex - 1);
}