You should TableModel ask for a TableModel , not a JTable , which can have its columns rearranged. One approach is to allow your TableModel implement a suitable interface, e.g.
public interface Quantifiable { public int getQuantity(int row); }
Application: Tell us how to implement this interface.
Much depends on the relationship between existing TableModel classes. Suppose everyone has a number in some column. If quantityCol is the model index, a column of type Number , you can do something like this:
public class QuantifiableTableModel extends AbstractTableModel implements Quantifiable { private int quantityCol; public QuantifiableTableModel(int quantityCol) { this.quantityCol = quantityCol; } @Override public int getQuantity(int row) { Number n = (Number) getValueAt(row, quantityCol); return n.intValue(); } ... }
source share