在java视图层添加表格,如何在设计视图中打开Java表单?

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).

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值