【发布时间】:2018-09-15 12:48:10
【问题描述】:
您是否有动态更改单元格颜色的建议,我在下面尝试过,但是当表格没有这些标签(“FAILURE”)时,即使该行仍保持彩色。当表格中不存在 FAILURE 标签时,我想恢复彩色单元格的颜色。
private static final String FAILURE = "FAILURE";
void example(){
final DefaultBodyLayerStack bodyLayer = underlyingLayer.getBodyLayer();
// Custom label "FAILURE" for cell
IConfigLabelAccumulator cellLabelAccumulator = new IConfigLabelAccumulator() {
Integer rowCount = null;
@Override
public void accumulateConfigLabels(LabelStack configLabels,
int columnPosition, int rowPosition) {
int rowIndex = bodyLayer.getRowIndexByPosition(rowPosition);
for (GridConsoleRow gridConsoleRow : underlyingLayer.getBodyDataProvider().getList()) {
if (StringUtils.equals(gridConsoleRow.getLogLevel().trim(), FAILURE)) {
rowCount = bodyLayer.getPreferredRowCount()-1;
break;
}
}
if (rowCount != null && rowIndex == rowCount.intValue()) {
configLabels.addLabel(FAILURE);
}
}
};
bodyLayer.setConfigLabelAccumulator(cellLabelAccumulator);
// Custom style for label "FAILURE"
natTable.addConfiguration(new AbstractRegistryConfiguration() {
@Override
public void configureRegistry(IConfigRegistry configRegistry) {
Style cellStyle = new Style();
cellStyle.setAttributeValue(
CellStyleAttributes.FOREGROUND_COLOR,
GUIHelper.COLOR_RED);
configRegistry.registerConfigAttribute(
CellConfigAttributes.CELL_STYLE, cellStyle,
DisplayMode.NORMAL, FAILURE);
}
});
}
【问题讨论】: