1

我对在 NatTable 单元格中使用图像有疑问。我的 ConfigLabelAccumulator 和 Configuration 看起来像这样

public class MyConfigLabelAccumulator implements IConfigLabelAccumulator {
  @Override
  public void accumulateConfigLabels(final LabelStack configLabels, final int columnPosition, final int rowPosition) {
    if (((rowPosition + columnPosition) % 2) == 0) {
      configLabels.addLabel("myLabel");
    }
  }
}

public class MyStyleConfiguration extends DefaultNatTableStyleConfiguration {
  @Override
  public void configureRegistry(final IConfigRegistry configRegistry) {
    super.configureRegistry(configRegistry);
    final Style style = new Style();
    style.setAttributeValue(CellStyleAttributes.IMAGE, GUIHelper.getImage("plus"));
    style.setAttributeValue(CellStyleAttributes.BACKGROUND_COLOR, GUIHelper.COLOR_YELLOW);
    configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_STYLE, style, DisplayMode.NORMAL, "myLabel");
    configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER, new CellPainterDecorator(new TextPainter(), CellEdgeEnum.RIGHT, new ImagePainter()), DisplayMode.NORMAL);
  }
}   

我这样配置

dataLayer.setConfigLabelAccumulator(new MyConfigLabelAccumulator());
...
natTable.addConfiguration(new MyStyleConfiguration());
...
natTable.configure();   

表看起来像预期的那样。我在单元格中看到黄色背景单元格和“+”图像。但打电话后

natTable.setTheme(new ModernNatTableThemeConfiguration());

我只看到黄色背景,没有图像。

UPD: 我已经解决了这个问题,IThemeExtension但可能还有另一种解决方案吗?

4

1 回答 1

2

主题配置旨在覆盖现有样式。这还允许在运行时切换主题。

IThemeExtensions 是使用条件样式扩展现有主题的方法。当然,您也可以通过扩展现有主题来创建自己的主题,但这样您的自定义就无法与其他主题一起使用。

上面代码中的问题似乎是您通常正在注册画家,而不仅仅是为您的“myLabel”。这是故意的吗?因为这会覆盖默认的单元格绘制器配置,然后再被主题覆盖。如果它应该只注册为“myLabel”设置主题不应该有效果。

于 2016-01-14T20:18:26.693 回答