gpt4 book ai didi

java - 将图像和背景添加到 NatTable 行

转载 作者:行者123 更新时间:2023-12-02 03:14:24 25 4
gpt4 key购买 nike

我已阅读以下文档:https://eclipse.org/nattable/documentation.php?page=styling

我很好奇是否有任何简单的方法可以使用单独的配置添加背景行颜色和图像。我不希望像 CellPainterWrapper 示例那样将它们组合成 1 个配置,因为我想将两者之间的逻辑分开。我当前的代码适用于图像或背景颜色,但我不能同时执行这两种操作(最顶部的配置覆盖最底部的配置)。以下是我的片段:

    void run(){
addBackgroundRowColors();
addImageToColumn();
}

void addImageToColumn() {
getNatTable().addConfiguration(new AbstractRegistryConfiguration() {
@Override
public void configureRegistry(IConfigRegistry configRegistry) {
final Style cellStyleOne = new Style();
cellStyleOne.setAttributeValue(CellStyleAttributes.IMAGE,
myIcon);
configRegistry.registerConfigAttribute(
CellConfigAttributes.CELL_STYLE, cellStyleOne,
DisplayMode.NORMAL, myIconLabel);

final Style cellStyleTwo = new Style();
cellStyleTwo.setAttributeValue(CellStyleAttributes.IMAGE,
myIcon2);
configRegistry.registerConfigAttribute(
CellConfigAttributes.CELL_STYLE, cellStyleTwo,
DisplayMode.NORMAL, myIconLabel2);

configRegistry.registerConfigAttribute(
CellConfigAttributes.CELL_PAINTER,
new CellPainterDecorator(new TextPainter(),
CellEdgeEnum.LEFT, 10, new ImagePainter()),
DisplayMode.NORMAL);
}
});
DataLayer dl = getGlazedListsGridLayer().getBodyDataLayer();
IConfigLabelAccumulator cellLabelAccumulator = (configLabels,
columnPosition, rowPosition) -> {
// Label code here...
};

dl.setConfigLabelAccumulator(cellLabelAccumulator);
}

void addBackgroundRowColors() {
getNatTable().addConfiguration(new AbstractRegistryConfiguration() {
@Override
public void configureRegistry(IConfigRegistry configRegistry) {
Style cellStyleOne = new Style();
cellStyleOne.setAttributeValue(
CellStyleAttributes.BACKGROUND_COLOR, myColorOne);
configRegistry.registerConfigAttribute(
CellConfigAttributes.CELL_STYLE, cellStyleOne,
DisplayMode.NORMAL, myColorLabel1);

Style cellStyleTwo = new Style();
cellStyleTwo.setAttributeValue(
CellStyleAttributes.BACKGROUND_COLOR, cellStyleTwo);
configRegistry.registerConfigAttribute(
CellConfigAttributes.CELL_STYLE, cellStyleTwo,
DisplayMode.NORMAL, myColorLabel2);
}
});
DataLayer dl = getGlazedListsGridLayer().getBodyDataLayer();
IConfigLabelAccumulator cellLabelAccumulator = (configLabels,
columnPosition, rowPosition) -> {
// Label code here...
};

dl.setConfigLabelAccumulator(cellLabelAccumulator);
}

更新

我最终做了类似于以下的事情来使其工作:

  AggregateConfigLabelAccumulator aggregate = 
new AggregateConfigLabelAccumulator();
aggregate.add(addImageToColumn());
aggregate.add(addBackgroundRowColors());

getGlazedListsGridLayer().getBodyDataLayer().
setConfigLabelAccumulator(aggregate);

最佳答案

从评论中来看,真正的问题是如何支持分离的IConfigLabelAccumulator。由于每层只能注册一个 IConfigLabelAccumulator,因此有两种方法可以实现此目的:

  1. 在不同层注册不同的IConfigLabelAccumulator
  2. 使用 AggregateConfigLabelAccumulator,您可以在其中组合多个 IConfigLabelAccumulator

入门教程中也对此进行了解释: http://www.vogella.com/tutorials/NatTable/article.html

关于java - 将图像和背景添加到 NatTable 行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40537138/

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