Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/eclipse/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何在Eclipse RCP向导中显示错误消息?_Java_Eclipse_Swt_Eclipse Rcp_Jface - Fatal编程技术网

Java 如何在Eclipse RCP向导中显示错误消息?

Java 如何在Eclipse RCP向导中显示错误消息?,java,eclipse,swt,eclipse-rcp,jface,Java,Eclipse,Swt,Eclipse Rcp,Jface,我想显示一条错误消息,它出现在向导窗口顶部的向导中(如下面的屏幕截图中的“无法创建项目内容…”消息) 根据我在互联网上的发现,我必须使用方法setErrorMessage来完成这项工作 但它在我的向导类中不存在: import org.eclipse.jface.wizard.Wizard; public class MyWizard extends Wizard { public MyWizard() { super(); setErrorMess

我想显示一条错误消息,它出现在向导窗口顶部的向导中(如下面的屏幕截图中的“无法创建项目内容…”消息)

根据我在互联网上的发现,我必须使用方法
setErrorMessage
来完成这项工作

但它在我的向导类中不存在:

import org.eclipse.jface.wizard.Wizard;

public class MyWizard extends Wizard {
    public MyWizard() {
        super();

        setErrorMessage("Error message"); // No such method
        getContainer().getCurrentPage().setErrorMessage("Error message 2"); // This also doesn't exist
    }

如何设置向导的错误消息?

JFace的
向导有页面。您可以自己创建这些页面,扩展
向导页面
。在该类中,您将找到
setErrorMessage
API

一个更快的选择是使用不需要页面的
标题readialog
。您也可以在那里使用错误API


例子
setErrorMessage
WizardPage
中的一个方法,但它不包括在
IWizardPage
接口中,该接口由
IWizardContainer.getCurrentPage
返回

通常是您的向导页面类设置错误消息-它们可以调用
setErrorMessage(text)

import org.eclipse.jface.wizard.Wizard;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

/**
 * 
 * @author ggrec
 *
 */
public class TestWizard extends Wizard
{

    // ==================== 3. Static Methods ====================

    public static void main(final String[] args)
    {
        final Display display = new Display();
        final Shell shell = new Shell(display);
        shell.setLayout(new GridLayout(1, false));

        final WizardDialog dialog = new WizardDialog(shell, new TestWizard());
        dialog.open();

        if (!display.readAndDispatch())
            display.sleep();
        display.dispose();
    }


    // ==================== 4. Constructors ====================

    private TestWizard()
    {

    }


    // ==================== 5. Creators ====================

    @Override
    public void addPages()
    {
        addPage(new TestPage());
        // Or, you could make a local var out of the page, 
        // and set the error message here.
    }


    // ==================== 6. Action Methods ====================

    @Override
    public boolean performFinish()
    {
        return true;
    } 


    // =======================================================
    //           19. Inline Classes 
    // =======================================================

    private class TestPage extends WizardPage
    {

        private TestPage()
        {
            super(TestPage.class.getCanonicalName());
        }


        @Override
        public void createControl(final Composite parent)
        {
            setControl(new Composite(parent, SWT.NULL));
            setErrorMessage("HOUSTON, WE'RE GOING DOWN !!!!!");
        }

    }

}