如何在设计视图中打开Java表单?

Dou*_*auf 1 eclipse

我在互联网上找到了这个代码.我正在我的新笔记本电脑上设置一个新的Eclipse,我希望能够在设计视图中打开它.

如何在设计视图中使用JComponents打开一个类,还有一种方法可以将其设置为默认值吗?

看起来似乎很容易,但我一直在Eclipse中寻找这个我们的更好的部分.我以为它是在Open With ...但我没有看到任何听起来像设计视图的东西.

我希望这是一个很好的问题因为我不能简单地找到设计视图按钮.

码:

package TestMenu;

import javax.swing.JFrame;
import javax.swing.JLabel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.SwingUtilities;

public class StartupWindow extends JFrame implements ActionListener
{
    private static final long serialVersionUID = 1L;
    private JButton btn;

    public StartupWindow()
    {
        super("Simple GUI");
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        btn = new JButton("Open the other JFrame!");
        btn.addActionListener(this);
        btn.setActionCommand("Open");
        add(btn);
        pack();

    }

    @Override
    public void actionPerformed(ActionEvent e)
    {
        String cmd = e.getActionCommand();

        if(cmd.equals("Open"))
        {
            dispose();
            new AnotherJFrame();
        }
    }

    public static void main(String[] args)
    {
        SwingUtilities.invokeLater(new Runnable(){

            @Override
            public void run()
            {
                new StartupWindow().setVisible(true);
            }

        });
    }
}

class AnotherJFrame extends JFrame
{
    private static final long serialVersionUID = 1L;

    public AnotherJFrame()
    {
        super("Another GUI");
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        add(new JLabel("Empty JFrame"));
        pack();
        setVisible(true);
    }
}
Run Code Online (Sandbox Code Playgroud)

s.d*_*s.d 11

如果通过"设计视图"表示Eclipse Windowbuilder,则可以使用"Open with ...">"WindowBuilder Editor"打开它.不过,我已经测试了开普勒SR1的Eclipse在Mac OS X代码,并得到了在设计视图,我猜意味着你将不能够使用它在设计视图以下错误消息原样.

解析器解析了编译单元,但无法识别任何GUI工具包,因此WindowBuilder无法显示任何要编辑的GUI.

在你的情况下,我尝试从向导创建一个新的WindowBuilder类,并从头开始重新创建类,例如,在设计视图中.

如果您根本无法在Open with ...菜单中找到WindowBuilder编辑器选项,或许您需要先在新的Eclipse实例中安装WindowBuilder.要执行此操作,请访问https://www.eclipse.org/windowbuilder/download.php,为您的Eclipse 版本选择发布版本更新站点的链接(Kepler SR1的链接为http://download.eclipse .org/windowbuilder/WB/release/R201309271200/4.3 /),并通过"安装新软件"安装(或按照更新站点链接中的说明进行操作,其中包括全面的安装详细信息).