下面列出了javax.swing.table.TableColumn#setModelIndex ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public void moveColumn(int fromIndex, int toIndex) {
TableColumn from = columnList.get(fromIndex);
TableColumn to = columnList.get(toIndex);
columnList.set(fromIndex, to);
to.setModelIndex(fromIndex);
columnList.set(toIndex, from);
from.setModelIndex(toIndex);
orderUpdate();
for (TableColumnModelListener w : new ArrayList<>(watchers)) {
w.columnMoved(new TableColumnModelEvent(this, fromIndex, toIndex));
}
}
public ProductEntryTableModel(final ProductEntry[] productList, boolean minimalView) {
this.productEntryList = productList;
dataProviders.add(new IDProvider());
dataProviders.add(new PropertiesProvider(minimalView));
if (!minimalView) {
try {
dataProviders.add(new QuicklookProvider());
} catch (Exception e) {
e.printStackTrace();
Dialogs.showError(e.getMessage());
}
}
for (final DataProvider provider : dataProviders) {
final TableColumn tableColumn = provider.getTableColumn();
tableColumn.setModelIndex(getColumnCount());
columnList.add(tableColumn);
}
}
public void removeColumn(int index) {
TableColumn column = getColumnModel().getColumn(index);
int modelIndex = column.getModelIndex();
Vector<?> modelData = model.getDataVector();
Vector<?> columnIdentifiers = model.getColumnIdentifiers();
// remove the column from the table
removeColumn(column);
// remove the column header from the table model
columnIdentifiers.removeElementAt(modelIndex);
// remove the column data
for (Object row : modelData) {
((Vector<?>) row).removeElementAt(modelIndex);
}
model.setDataVector(modelData, columnIdentifiers);
// correct the model indices in the TableColumn objects
Enumeration<TableColumn> columns = getColumnModel().getColumns();
while (columns.hasMoreElements()) {
TableColumn currentColumn = columns.nextElement();
if (currentColumn.getModelIndex() >= modelIndex) {
currentColumn.setModelIndex(currentColumn.getModelIndex() - 1);
}
}
}
public AOITableModel(final AOI[] aoiList) {
this.aoiList = aoiList;
//dataProviders.add(new IDProvider());
dataProviders.add(new AOIDetailsProvider());
for (final DataProvider provider : dataProviders) {
final TableColumn tableColumn = provider.getTableColumn();
tableColumn.setModelIndex(getColumnCount());
columnList.add(tableColumn);
}
}