【发布时间】:2021-09-01 10:39:44
【问题描述】:
我有一个带有不同列和行的网表,其中填充了数据。当在文本字段中搜索某些文本时,我想突出显示单元格中的特定文本。
查看https://www.eclipse.org/nattable/nandn/nandn_150.php后 我尝试了以下操作,但按下应用按钮时没有突出显示
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 + ")");
}
因此,我假设当我在文本字段中键入内容并单击文本字段中提供的单元格中的应用按钮时,文本应突出显示,但没有任何更改。有什么帮助吗?
谢谢
【问题讨论】:
标签: java eclipse eclipse-rcp nattable