Java 使用swing设计eclipse菜单

Java 使用swing设计eclipse菜单,java,eclipse,swing,eclipse-plugin,Java,Eclipse,Swing,Eclipse Plugin,作为家庭作业的一部分,我必须创建一个文档生成器 我决定将它实现为一个eclipse插件,但是我遇到了一点问题 基本上我想要的是有一个名为DocPreferences的新菜单,当用户点击它时,它会显示一个窗口,询问HTML页面的首选项,如背景色、图像等 因此,我在Swing中创建了一个窗口来收集用户的信息,每当调用菜单的事件处理程序时,我都会创建Swing类的一个对象并调用它来显示菜单 然后,我以eclipse应用程序的形式运行该项目,当我点击窗口时,确实显示了我在swing中设计的UI。但是,当

作为家庭作业的一部分,我必须创建一个文档生成器

我决定将它实现为一个eclipse插件,但是我遇到了一点问题

基本上我想要的是有一个名为DocPreferences的新菜单,当用户点击它时,它会显示一个窗口,询问HTML页面的首选项,如背景色、图像等

因此,我在Swing中创建了一个窗口来收集用户的信息,每当调用菜单的事件处理程序时,我都会创建Swing类的一个对象并调用它来显示菜单

然后,我以eclipse应用程序的形式运行该项目,当我点击窗口时,确实显示了我在swing中设计的UI。但是,当我单击UI菜单上的[close]按钮时,它也关闭了运行它的eclipse应用程序。有没有关于如何解决这个问题的帮助

另外,我还想提到,我的所有UI都是使用UI生成器在swing中设计的,因为我对SWT一无所知,所以我更希望有一种方法可以解决我的问题,而不必在SWT中重做所有工作

    //This code is part of a class called ColorChooser
    private void initComponents() {

    colorChooser = new javax.swing.JColorChooser();
    submit = new javax.swing.JButton();
    cancel = new javax.swing.JButton();
    label = new javax.swing.JLabel();

    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
    //Then I set the layout of the components

    //This is the method which is invoked to start the application
    public void runner() {
    try {
        for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
            if ("Nimbus".equals(info.getName())) {
                javax.swing.UIManager.setLookAndFeel(info.getClassName());
                break;
            }
        }
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    java.awt.EventQueue.invokeLater(new Runnable() {
        public void run() {
            new ColorChooser().setVisible(true);
        }
    });
}                  

//Finally in my handler class for the eclipse plugin the body of the execute method
public Object execute(ExecutionEvent event) throws ExecutionException {
    new ColorChooser().runner();
    return null;
}

Close按钮是Eclipse生成的还是由UI生成器创建的?Close按钮是窗口顶部的按钮,我们为其编写setDefaultCloseOperationJFrame.EXIT_on_Close。您可以发布任何代码吗?特别是,关于您提到的setDefaultCloseOperation方法,我已经编辑了问题并添加了您要求的代码。我希望这有助于找到问题的根源。