0

I intent to use a TableModelListener to react on user entries of a JTable. I would like to know the column of the edited cell. Unfortunately, the method getColumn() returns -1 instead of the edited column number. Any idea why?

public class TableEventListener implements TableModelListener {

    @Override
    public void tableChanged(TableModelEvent e) {

        if (e.getType() == TableModelEvent.UPDATE ) {
            System.out.println(e.getColumn());  //prints -1
        }
    }
}
trashgod
  • 203,806
  • 29
  • 246
  • 1,045
pen
  • 1
  • 1
  • Post a proper [SSCCE](http://sscce.org/) when asking a question. Without seeing the context of how the code is used it is hard to guess what you are doing wrong. Check out this simple SSCCE that works fine using a TableModelListener: http://stackoverflow.com/questions/3540661/tablemodellistener-and-multiple-column-validation/3541876#3541876 – camickr Aug 14 '15 at 14:46

1 Answers1

1

As noted in the TableModelEvent API for getColumn(), "If the return value is ALL_COLUMNS; it means every column in the specified rows changed." Note that ALL_COLUMNS has the value -1.

trashgod
  • 203,806
  • 29
  • 246
  • 1,045