带有样式文本的 jface 组合框内容提案

问题描述

现在我有一个包含基于组合值的内容提案的组合框:提案仅列出与组合框中的子字符串匹配的条目。

enter image description here

我希望对提案进行样式设置(例如,匹配的子字符串以粗体显示),例如 Eclipse IDE 中的自动完成建议。

enter image description here

但是我被卡住了,因为 ContentPropostalAdapter 似乎只接受 ILabelProvider 实现作为 LabelProviders(而不是 IStyledLabelProvider 例如)。

有没有办法实现带样式的建议框?

自动完成组合

public class AutoCompleteCombo {

public static void main(String[] args) {

    display display = new display();
    Shell shell = new Shell(display);
    shell.setLayout(new GridLayout(1,false));
    shell.setLayoutData(new GridData(SWT.FILL,SWT.FILL,true,false));
    shell.setSize(200,200);
    shell.setText("Auto Complete Combo");

    Combo combo = new Combo(shell,SWT.NONE);

    SubstringMatchContentProposalProvider provider = new SubstringMatchContentProposalProvider();
    String[] proposals = { "ProposalOne","ProposalTwo","ProposalThree" };

    provider.setProposals(Arrays.asList(proposals));
    ContentProposalAdapter cpa = new ContentProposalAdapter(combo,new ComboContentAdapter(),provider,null,null);

    cpa.setLabelProvider(new SampleLabelProvider());
    cpa.setProposalAcceptanceStyle(ContentProposalAdapter.PROPOSAL_REPLACE);

    shell.open();
    while (!shell.isdisposed()) {
        if (!display.readAnddispatch())
            display.sleep();
    }
    display.dispose();

}
}

SampleLabelProvider

public class SampleLabelProvider implements ILabelProvider {

private static final Image IMAGE1= new Image(display.getDefault(),display.getDefault().getSystemImage(SWT.ICON_WARNING).getimageData().scaledTo(16,16));

@Override
public Image getimage(Object arg0) {
    return IMAGE1;
}

@Override
public String getText(Object arg0) {
    if (arg0 instanceof ContentProposal)
        return ((ContentProposal)arg0).getContent();
        else
        return "";
}
//...
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)