Here you can find the source of insertTableModelListener(TableModel model, TableModelListener l, int index)
Parameter | Description |
---|---|
model | the AbstractTableModel |
l | the TableModelListener to be inserted |
index | the index. |
public static void insertTableModelListener(TableModel model, TableModelListener l, int index)
//package com.java2s; import javax.swing.event.TableModelListener; import javax.swing.table.AbstractTableModel; import javax.swing.table.TableModel; public class Main { /**//from ww w. j a v a2 s .c o m * Inserts the table model listener at the particular index in the listeners' chain. The listeners are fired in * reverse order. So the listener at index 0 will be fired at last. * * @param model the AbstractTableModel * @param l the TableModelListener to be inserted * @param index the index. */ public static void insertTableModelListener(TableModel model, TableModelListener l, int index) { if (!(model instanceof AbstractTableModel)) { model.addTableModelListener(l); return; } TableModelListener[] listeners = ((AbstractTableModel) model) .getTableModelListeners(); for (TableModelListener listener : listeners) { model.removeTableModelListener(listener); } for (int i = 0; i < listeners.length; i++) { TableModelListener listener = listeners[i]; if (index == i) { model.addTableModelListener(l); } model.addTableModelListener(listener); } // index is too large, add to the end. if (index < 0 || index > listeners.length - 1) { model.addTableModelListener(l); } } }