gpt4 book ai didi

java - 动态更改 NatTable 中特定单元格的行前景色

转载 作者:太空宇宙 更新时间:2023-11-04 10:34:00 25 4
gpt4 key购买 nike

您对动态更改单元格颜色有什么建议吗?我在下面尝试过,但是当表格没有这些标签(“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);

}
});
}

最佳答案

你调试过FAILURE标签真的不存在吗? NatTable 仅显示应有的内容,因此,如果您仅为 FAILURE 标签注册了具有红色背景的样式,则它将仅呈现具有该标签的红色行。老实说,我不明白你的 IConfigLabelAccumulator 的逻辑。原因可能是 rowCount 成员,因为如果没有失败,您再也不会将其设置回 null 。不确定为什么您将该信息存储在成员变量中。

关于java - 动态更改 NatTable 中特定单元格的行前景色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49676722/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com