如何更改ContentProposalAdapter的外观

时间:2011-09-02 03:40:30

标签: java swt jface

我正在使用ContentProposalAdapter来自动完成文本框,它工作正常,但我想改变其外观,如弹出的字体或背景颜色等等,我搜索但我找不到任何ContentProposalAdapter的方法这些东西。如何更改ContentProposalAdapter的外观?

2 个答案:

答案 0 :(得分:3)

我对此jface部分没有任何经验,但是当您查看文档时,您可以找到方法openProposalPopupsee docs

此类提供了一些可覆盖的方法,允许客户端手动控制弹出窗口。但是,大多数实施仍然是私有的。

打开提案弹出窗口并显示提案提供商提供的提案。此方法立即返回。也就是说,它不会等待选择提案。子类使用此方法显式调用弹出窗口的打开。如果没有要显示的提案,弹出窗口将不会打开,并且会发出蜂鸣声。

如果您检查此方法的代码,您将找到

/**
 * Open the proposal popup and display the proposals provided by the
 * proposal provider. If there are no proposals to be shown, do not show the
 * popup. This method returns immediately. That is, it does not wait for the
 * popup to open or a proposal to be selected.
 * 
 * @param autoActivated
 *            a boolean indicating whether the popup was autoactivated. If
 *            false, a beep will sound when no proposals can be shown.
 */
private void openProposalPopup(boolean autoActivated) {
    if (isValid()) {
        if (popup == null) {
            // Check whether there are any proposals to be shown.
            recordCursorPosition(); // must be done before getting proposals
            IContentProposal[] proposals = getProposals();
            if (proposals.length > 0) {
                if (DEBUG) {
                    System.out.println("POPUP OPENED BY PRECEDING EVENT"); //$NON-NLS-1$
                }
                recordCursorPosition();
                popup = new ContentProposalPopup(null, proposals);
                popup.open();
                popup.getShell().addDisposeListener(new DisposeListener() {
                    public void widgetDisposed(DisposeEvent event) {
                        popup = null;
                    }
                });
                internalPopupOpened();
                notifyPopupOpened();
            } else if (!autoActivated) {
                getControl().getDisplay().beep();
            }
        }
    }
}

/**
 * Open the proposal popup and display the proposals provided by the
 * proposal provider. This method returns immediately. That is, it does not
 * wait for a proposal to be selected. This method is used by subclasses to
 * explicitly invoke the opening of the popup. If there are no proposals to
 * show, the popup will not open and a beep will be sounded.
 */
protected void openProposalPopup() {
    openProposalPopup(false);
}

代码创建ContentProposalPopup实例,它管理弹出窗口小部件的外观以及其他一些事物(see source code of whole ContentProposalAdapeter class)。

因此,如果您要创建将覆盖openProposalPopup()并将使用您自己的ContentProposalPopup的新课程,则可以根据需要管理外观。

答案 1 :(得分:1)

我们也遇到了ContentProposalAdapter的问题,最后复制粘贴它,然后根据我们的需要进行修改。