eclipse 如何在设计视图中打开 Java 表单?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23504813/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to open a Java form in design view?
提问by Doug Hauf
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.
我在网上找到了这段代码。我正在我的新笔记本电脑上设置一个新的 Eclipse,我希望能够在设计视图中打开它。
How do you open a class with JComponents' on it in design view and also is there a way to make that the default?
你如何在设计视图中打开一个带有 JComponents 的类,还有没有办法让它成为默认值?
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.
看起来很简单的事情,但我一直在 Eclipse 中寻找这个,以便我们更好地了解它。我以为它是在 Open With 中...但我没有看到任何听起来像设计视图的东西。
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);
}
}
回答by s.d
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.
如果“设计视图”是指Eclipse Windowbuilder,则可以使用“Open with ...”>“WindowBuilder Editor”打开它。但是,我已经在 Mac OS X 上使用 Kepler SR1 Eclipse 测试了您的代码,并在设计视图中收到以下错误消息,我猜这意味着您将无法在设计视图中按原样使用它。
The parser parsed the compilation unit, but can't identify any GUI toolkit, so WindowBuilder can't display any GUI to edit.
解析器解析了编译单元,但无法识别任何 GUI 工具包,因此 WindowBuilder 无法显示任何 GUI 进行编辑。
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.
在您的情况下,我会尝试从向导创建一个新的 WindowBuilder 类,然后从头开始重新创建该类,例如,在Design View 中。
In case you cannot find the option WindowBuilder Editorin 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 sitefor 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).
如果您根本找不到Open with ...菜单中的WindowBuilder Editor选项,也许您需要先在新的 Eclipse 实例中安装 WindowBuilder。为此,请转到https://www.eclipse.org/windowbuilder/download.php,选择指向您的 Eclipse 版本的发布版本更新站点的链接(Kepler SR1 的站点是http://download.eclipse .org/windowbuilder/WB/release/R201309271200/4.3/),并通过“安装新软件”进行安装(或按照更新站点链接中的说明进行操作,其中包括全面的安装详细信息)。
回答by bravohex
In Eclipse go to Menu/Help/Install New Software. Put link you want to install there and(enter if it's not refresh)
在 Eclipse 中,转到菜单/帮助/安装新软件。把你想安装的链接放在那里(如果没有刷新,请输入)
You can get link here: https://www.eclipse.org/windowbuilder/
您可以在此处获取链接:https: //www.eclipse.org/windowbuilder/
回答by CraftedGaming
This may be too late but I also had a hard time looking for the design tab on the internet. It's not stated on the links I've went to. Basically, head over to the tab that you created with WindowBuilder with the code and look at the bottom of your screen. I have a picture just so everyone can have a reference of it.
这可能为时已晚,但我也很难在互联网上寻找设计标签。我访问的链接中没有说明。基本上,转到您使用 WindowBuilder 创建的带有代码的选项卡,然后查看屏幕底部。我有一张图,大家可以参考一下。
Depending on your perspective or how you setup your tabs, it should be right under the text editor.
回答by Avelino V. Pangilinan Jr
Right click on the class -> Open With -> WindowBuilder Editor
右键单击类 -> 打开方式 -> WindowBuilder Editor