I have a nettable with different columns and rows filled with data. I want to highlight specific text in cells when some text is searched in a text field.
After lookin into https://www.eclipse.org/nattable/nandn/nandn_150.php I tried the following but nothing is highlighted when I press the apply button
this.applyButton = new Button(parent, SWT.PUSH);
this.applyButton.addSelectionListener(getSelectionListener());
private SelectionListener getSelectionListener(){
return new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
String text = textBox.getText();
if(!text.trim().isEmpty()) {
applyHighlighting(text);
}
}
};
}
public void applyHighlighting(String text) {
RegexMarkupValue regexMarkup = new RegexMarkupValue("", "<span style=\"background-color:rgb(255, 255, 0)\">",
"</span>");
natTable.addConfiguration(new DefaultNatTableStyleConfiguration() {
{
this.cellPainter = new BackgroundPainter(new PaddingDecorator(new RichTextCellPainter(), 2));
}
@Override
public void configureRegistry(IConfigRegistry configRegistry) {
super.configureRegistry(configRegistry);
// markup for highlighting
MarkupDisplayConverter markupConverter = new MarkupDisplayConverter();
markupConverter.registerMarkup("highlight", regexMarkup);
// register markup display converter for normal display mode in the body
configRegistry.registerConfigAttribute(CellConfigAttributes.DISPLAY_CONVERTER, markupConverter,
DisplayMode.NORMAL, GridRegion.BODY);
}
});
regexMarkup.setRegexValue(text.isEmpty() ? "" : "(" + text + ")");
}
so with this I assumed when I type something in the text field and click on apply button text in the cells provided in the text field should be highlighted but nothing is changed. Any help?
Thanks
If you only want to highlight parts of a text inside a cell, you need the Nebula Extension. It is described in the New & Noteworthy of 1.5
https://www.eclipse.org/nattable/nandn/nandn_150.php
There is also a pointer to the corresponding example.