突出显示 nattable 单元格中的文本

Highlight text in nattable cell

我有一个包含不同列和行的网络表,其中填充了数据。当在文本字段中搜索某些文本时,我想突出显示单元格中的特定文本。

调查后 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

还有一个指向相应示例的指针。