SubTableModelListener implements TableModelListener { @Override public void tableChanged(@NotNull TableModelEvent event) { int delegateColumnIndex = event.getColumn(); if (delegateColumnIndex == TableModelEvent.ALL_COLUMNS) { myDelegate.tableChanged(new TableModelEvent( myModel, event.getFirstRow(), event.getLastRow(), TableModelEvent.ALL_COLUMNS, event.getType())); return; } if (!(myModel.getStartColumnSupplier().getAsInt() <= delegateColumnIndex && delegateColumnIndex < myModel.getEndColumnSupplier().getAsInt())) { return; } myDelegate.tableChanged(new TableModelEvent( myModel, event.getFirstRow(), event.getLastRow(), myModel.convertColumnIndexToModel(delegateColumnIndex), event.getType())); } SubTableModelListener(@NotNull SubTableModel model, @NotNull TableModelListener delegate); @Override void tableChanged(@NotNull TableModelEvent event);  }
@Test public void tableChangedDelegateColumnIndexEqualsAllColumns() { TableModel delegateModel = new DefaultTableModel(1, 4); SubTableModel model = new SubTableModel(delegateModel, () -> 0, () -> delegateModel.getColumnCount()); TableModelListener delegateListener = Mockito.mock(TableModelListener.class); new SubTableModelListener(model, delegateListener).tableChanged(new TableModelEvent(delegateModel)); Mockito.verify(delegateListener).tableChanged(ArgumentMatchers.argThat(new TableModelEventArgumentMatcher(new TableModelEvent(model)))); }