如何在设计视图中打开Java表单? [英] How to open a Java form in design view?

查看:321
本文介绍了如何在设计视图中打开Java表单?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在互联网上发现了这个代码。我在我的新笔记本电脑上设置了一个新的Eclipse,我想在设计视图中打开它。



如何在设计视图中打开一个带有JComponents的类,还有一种方法可以使它成为默认值?



看起来很容易,但我一直在寻找这个在Eclipse中更好的部分。我以为是在开放...但我没有看到任何听起来像设计视图。



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



代码:

  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;
私人JButton btn;

public StartupWindow()
{
super(简单GUI);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

btn = new JButton(打开其他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(另一个GUI);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

add(new JLabel(Empty JFrame));
pack();
setVisible(true);
}
}


解决方案

通过设计视图,您的意思是 Eclipse Windowbuilder ,您可以使用Open with ...>WindowBuilder Editor 。但是,我已经使用Mac OS X上的Kepler SR1 Eclipse测试了您的代码,并在设计视图中收到以下错误消息,我猜这意味着您将无法在设计视图中使用它是。


解析器解析了编译单元,但无法识别任何GUI工具包,因此WindowBuilder无法显示任何GUI进行编辑。 / p>

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



如果您在打开方式找不到WindowBuilder编辑器 ... 菜单,或许您需要首先在新的Eclipse实例中安装WindowBuilder。要执行此操作,请转到 https://www.eclipse.org/windowbuilder/download.php ,选择链接到您的Eclipse版本的版本更新站点(Kepler SR1的版本为 http://download.eclipse.org/windowbuilder/WB/release/R201309271200/4.3/ ),并通过安装新软件安装(或按照更新站点链接中的说明进行安装,其中包括综合安装细节)。


I found this code on the internet. I am setting up a new Eclipse on my new laptop and I want to be able to open this in design view.

How do you open a class with JComponents' on it in design view and also is there a way to make that the default?

Seems like and easy thing but I have been looking for this in Eclipse for the better part of an our. I thought it was in Open With... but I didn't see anything that that sounded like design view.

I hope this is a good question because I just cannot simple find the design view button.

code:

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);
    }
}

解决方案

If by "design view" you mean the Eclipse Windowbuilder, you can open that with "Open with ..." > "WindowBuilder Editor." However, I have tested your code with a Kepler SR1 Eclipse on Mac OS X, and got the following error message in the Design View, which I guess means that you won't be able to use it in the Design View as is.

The parser parsed the compilation unit, but can't identify any GUI toolkit, so WindowBuilder can't display any GUI to edit.

In your case I'd try to create a new WindowBuilder class from the wizard, and re-create the class from scratch, e.g., in the Design View.

In case you cannot find the option WindowBuilder Editor in the Open with ... menu at all, perhaps you'll need to install WindowBuilder in your new Eclipse instance first. To do this, go to https://www.eclipse.org/windowbuilder/download.php, pick the link to the release version update site for your version of Eclipse (the one for Kepler SR1 is http://download.eclipse.org/windowbuilder/WB/release/R201309271200/4.3/), and install via "Install New Software" (or follow the instructions from the update site link, which includes comprehensive installation details).

这篇关于如何在设计视图中打开Java表单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆