问题描述
我有一个用不同列和行填充数据的网络表。当在文本字段中搜索某些文本时,我想突出显示单元格中的特定文本。
调查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 + ")");
}
因此,我假设当我在文本字段中键入内容并单击文本字段中提供的单元格中的应用按钮文本时,应该突出显示但没有任何更改。有什么帮助吗?
谢谢
解决方法
如果您只想突出显示单元格内的部分文本,则需要 Nebula Extension。它在 1.5 的 New & Noteworthy 中有描述
https://www.eclipse.org/nattable/nandn/nandn_150.php
还有一个指向相应示例的指针。