I have question regarding using images in NatTable cells. My ConfigLabelAccumulator and Configuration looks like this
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);
}
}
And I configure it this way
dataLayer.setConfigLabelAccumulator(new MyConfigLabelAccumulator());
...
natTable.addConfiguration(new MyStyleConfiguration());
...
natTable.configure();
Table looks like expected. I see yellow background cells and "+" image in cells. But after call
natTable.setTheme(new ModernNatTableThemeConfiguration());
I see only yellow background and no image.
UPD:
I've solved this using IThemeExtension
but may be there is another solution?
Theme configurations are intended to override existing stylings. This allows to also switch a theme at runtime.
IThemeExtensions are the way to extend an existing theme with conditional stylings. You can of course also create your own theme by extending an existimg one, but this way your customization is not resuable with other themes.
The problem in the above code seems to be that you are registering the painter in general and not only for your "myLabel". Is that intended? Because this overrides the default cell painter configuration, which is then again overriden by the theme. If it should only be registered for "myLabel" setting the theme should not have an effect.