アプリケーションのいくつかの異なるテーブルに Nattable を使用しています。ここで、最初の列の行番号を削除する方法を見つける必要があります。テーブルから行番号を非表示/削除する方法はありますか?
テーブルを描画するための私のソースは次のとおりです。
public void generate() {
ConfigRegistry configRegistry = new ConfigRegistry();
ColumnGroupModel columnGroupModel = new ColumnGroupModel();
ColumnGroupModel columnGroupGroup = new ColumnGroupModel();
bodyLayer = new BodyLayerStack<T>(this.expandTree, getItems(), columnPropertyAccessor, configRegistry,
treeformat);
columnLabelAccumulator = new CustomLabelAccumulator(bodyLayer.getBodyDataLayer(),
(ListDataProvider<T>) bodyLayer.getBodyDataProvider());
applyColumnLabels(columnDefinitions, columnLabelAccumulator);
bodyLayer.getBodyDataLayer().setConfigLabelAccumulator(columnLabelAccumulator);
// create the column header layer stack
IDataProvider columnHeaderDataProvider = new NATColumnHeaderDataProvider(columnDefinitions);
DataLayer columnHeaderDataLayer = new DataLayer(columnHeaderDataProvider);
ColumnHeaderLayer columnHeaderLayer = new ColumnHeaderLayer(columnHeaderDataLayer, bodyLayer,
bodyLayer.getSelectionLayer());
ILayer columnHeaderToUse = null;
if (sortEnabled) {
SortHeaderLayer<T> sortHeaderLayer = new SortHeaderLayer<T>(columnHeaderLayer, new GlazedListsSortModel<T>(
bodyLayer.getSortedList(), columnPropertyAccessor, configRegistry, columnHeaderDataLayer));
columnGroupHeaderLayer = new ColumnGroupHeaderLayer(sortHeaderLayer, bodyLayer.getSelectionLayer(),
columnGroupModel);
columnHeaderToUse = sortHeaderLayer;
} else {
columnGroupHeaderLayer = new ColumnGroupHeaderLayer(columnHeaderLayer, bodyLayer.getSelectionLayer(),
columnGroupModel);
columnHeaderToUse = columnGroupHeaderLayer;
}
columnGroupGroupHeaderLayer = new ColumnGroupGroupHeaderLayer(columnGroupHeaderLayer,
bodyLayer.getSelectionLayer(), columnGroupGroup);
applyColumnWidths(bodyLayer.getBodyDataLayer());
applyColumnHeaderGroups();
// Note: The column header layer is wrapped in a filter row composite.
// This plugs in the filter row functionality
DefaultGlazedListsStaticFilterStrategy<T> filterStrategy = new DefaultGlazedListsStaticFilterStrategy<T>(
bodyLayer.getFilterList(), columnPropertyAccessor, configRegistry);
for (int i = 0; i < staticFilters.size(); i++) {
filterStrategy.addStaticFilter(staticFilters.get(i));
}
if (showHeaderGroupRow) {
columnHeaderToUse = columnGroupHeaderLayer;
if (showHeaderGroupGroupsRow)
columnHeaderToUse = columnGroupGroupHeaderLayer;
}
FilterRowHeaderComposite<T> filterRowHeaderLayer = new FilterRowHeaderComposite<T>(filterStrategy,
columnHeaderToUse, columnHeaderDataLayer.getDataProvider(), configRegistry);
ILayer finalHeaderRow = columnHeaderToUse;
if (showFilterRow) {
finalHeaderRow = filterRowHeaderLayer;
}
// build the row header layer
DefaultRowHeaderDataProvider rowHeaderDataProvider = new DefaultRowHeaderDataProvider(
bodyLayer.getBodyDataProvider());
DataLayer rowHeaderDataLayer = new DataLayer(rowHeaderDataProvider);
rowHeaderDataLayer.setDefaultColumnWidth(40);
ILayer rowHeaderLayer = new RowHeaderLayer(rowHeaderDataLayer, bodyLayer, bodyLayer.getSelectionLayer());
// build the corner layer
ILayer cornerLayer = new CornerLayer(
new DataLayer(new DefaultCornerDataProvider(columnHeaderDataProvider, rowHeaderDataProvider)),
rowHeaderLayer, finalHeaderRow);
// build the grid layer
compositeGridLayer = new GridLayer(bodyLayer, finalHeaderRow, rowHeaderLayer, cornerLayer);
if (editorConfiguration != null) {
compositeGridLayer.addConfiguration(editorConfiguration);
}
natTable = new NatTable(parent, compositeGridLayer, false);
natTable.setConfigRegistry(configRegistry);
natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
compositeGridLayer.registerCommandHandler(new LandscapePrintHandler(compositeGridLayer));
addStyling();
natTable.addLayerListener(new ILayerListener() {
@Override
public void handleLayerEvent(ILayerEvent event) {
int rowNumber = -1;
int columnNumber = -1;
if (event instanceof CellVisualChangeEvent && !(event instanceof CellSelectionEvent)) {
CellVisualChangeEvent visualChangeEvent = (CellVisualChangeEvent) event;
rowNumber = visualChangeEvent.getRowPosition();
columnNumber = visualChangeEvent.getColumnPosition();
ListDataProvider<T> dataProvider = (ListDataProvider<T>) bodyLayer.getBodyDataProvider();
int transformedRow = LayerUtil.convertRowPosition(compositeGridLayer, selectedRow,
bodyLayer.getBodyDataLayer());
T newObject = dataProvider.getRowObject(transformedRow);
notifyModificationListeners(newObject, getSelectedItem());
}
if (event instanceof CellSelectionEvent) {
CellSelectionEvent cellEvent = (CellSelectionEvent) event;
rowNumber = cellEvent.getRowPosition();
columnNumber = cellEvent.getColumnPosition();
launchGridSelectionUpdated();
}
if (rowNumber > -1) {
ListDataProvider<T> dataProvider = (ListDataProvider<T>) bodyLayer.getBodyDataProvider();
int transformedRow = LayerUtil.convertRowPosition(compositeGridLayer, rowNumber,
bodyLayer.getBodyDataLayer());
T ob = dataProvider.getRowObject(transformedRow);
notifyItemSelectionlisteners(ob);
}
if (columnNumber > -1) {
int transformedColumn = LayerUtil.convertColumnPosition(compositeGridLayer, columnNumber,
bodyLayer.getBodyDataLayer());
selectedColumnPlaceholder.clear();
selectedColumnPlaceholder.add(columnDefinitions.get(transformedColumn));
}
if (rowNumber != -1 && columnNumber != -1) {
// First start of the selection process
ListDataProvider<T> dataProvider = (ListDataProvider<T>) bodyLayer.getBodyDataProvider();
int transformedRow = LayerUtil.convertRowPosition(compositeGridLayer, rowNumber,
bodyLayer.getBodyDataLayer());
setSelectedItem((T) Utils.cloneObject(dataProvider.getRowObject(transformedRow)));
selectedRow = rowNumber;
}
}
});
// add sorting configuration
natTable.addConfiguration(new SingleClickSortConfiguration());
natTable.configure();
// natTable.setTheme(new ModernNatTableThemeConfiguration());
ThemeConfiguration modernTheme = new ModernNatTableThemeConfiguration();
modernTheme.addThemeExtension(new CustomGroupByThemeExtension());
natTable.setTheme(modernTheme);
freezeColumns();
registerCopyHandlers(getSelectionLayer(), columnHeaderDataLayer);
natTable.addMouseListener(new MouseAdapter() {
@Override
public void mouseDown(MouseEvent e) {
if (e.button == MouseEventMatcher.RIGHT_BUTTON) {
int column = compositeGridLayer.getColumnPositionByX(e.x);
int row = bodyLayer.getBodyDataLayer().getRowPositionByY(e.y);
row = compositeGridLayer.getRowPositionByY(e.y);
ListDataProvider<T> dataProvider = bodyLayer.getBodyDataProvider();
int transformedRow = LayerUtil.convertRowPosition(compositeGridLayer, row,
bodyLayer.getBodyDataLayer());
if (transformedRow != -1) {
T item = dataProvider.getRowObject(transformedRow);
notifyRightClickListeners(e.x, e.y, item, getColumnDefinition(column));
}
}
}
});
attachToolTip();
}