gpt4 book ai didi

eclipse - 如何在设计 View 中打开Java窗体?

转载 作者:行者123 更新时间:2023-12-02 12:14:42 24 4
gpt4 key购买 nike

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

如何在设计 View 中打开带有 JComponents 的类,是否有办法将其设为默认值?

看起来很简单,但我一直在 Eclipse 中寻找这个,以获得我们的更好的部分。我以为它是在“打开方式”中...但我没有看到任何听起来像设计 View 的内容。

我希望这是一个好问题,因为我无法简单地找到设计 View 按钮。

代码:

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

最佳答案

如果“设计 View ”是指 Eclipse Windowbuilder ,您可以通过“打开方式...”>“WindowBuilder 编辑器”打开它。但是,我在 Mac OS X 上使用 Kepler SR1 Eclipse 测试了您的代码,并在设计 View 中收到以下错误消息,我猜这意味着您将无法在设计 View 中使用它是。

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

在您的情况下,我会尝试从向导创建一个新的 WindowBuilder 类,然后从头开始重新创建该类,例如,在“设计 View ”中。

如果您根本无法在“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/ ),然后通过“安装新软件”进行安装(或按照更新中的说明进行操作)站点链接,其中包括全面的安装详细信息)。

关于eclipse - 如何在设计 View 中打开Java窗体?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23504813/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com