[英]Dynamically change row foreground color of particular cell in NatTable
do you have nay suggestions to dynamically change the color of cell , I have tried below but when table does not have the those label ("FAILURE") even after that row will remains colored. 您是否有建议动态更改单元格的颜色,我在下面尝试过,但是当表格没有那些标签(“ FAILURE”)时,即使该行仍保持彩色后,我还是尝试过。 I want to revert back the color of colored cell when FAILURE label is not present in the table.
当表格中未出现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);
}
});
}
Have you debugged that the FAILURE label is really not present? 您是否调试过FAILURE标签确实不存在? NatTable only shows what it should, so if you registered the style with a red background only for the FAILURE label, it will only render rows in red that have that label.
NatTable仅显示应该显示的内容,因此,如果仅将FAILURE标签的样式注册为红色背景,则它将仅以红色显示具有该标签的行。 To be honest, I don't understand the logic of your
IConfigLabelAccumulator
. 老实说,我不了解您的
IConfigLabelAccumulator
的逻辑。 Probably the rowCount
member is the cause, as you never set it back to null
again if there is no failure. rowCount
成员可能是原因,因为如果没有失败,则永远不要将其重新设置为null
。 Not sure why you anyhow store that information in a member variable. 不知道为什么要以任何方式将这些信息存储在成员变量中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.