【发布时间】:2020-05-12 17:42:19
【问题描述】:
我是 Intellij IDEA(社区版 2020.1)的新手,我想尝试一个简单的 JSwing 表单。表单在运行时显示良好,但问题出在 GUI 编辑器/设计器上,如果我尝试预览表单,它会显示“无法加载 FormPreviewFrame.class”
我还有一个补充问题,我看到在 GUI Designer 中创建了一个默认的 JPanel,这是创建的 JFrame 的默认内容窗格吗?我的意思是我需要将该 JPanel 添加到 JFrame 中吗? (尽管它在没有添加的情况下工作)
已编辑更新:我认为这是一个尚未修复的旧错误,如 HERE 和 HERE 所述
以下是我的简单JFrame,我将“MyMainForm”类绑定到UI Form(.form)
class MyMainForm extends JFrame{
private JPanel panel;
private JLabel lbl;
private JButton btn;
public MyMainForm(String title) throws HeadlessException {
super(title);
//setSize( 150, 100 );
setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
this.panel = new JPanel();
this.lbl = new JLabel("Result");
this.btn = new JButton("Calculate");
panel.setBackground(Color.blue);
this.setLayout(new FlowLayout());
this.setBounds(400,200,500,500);
add(lbl);
add(btn);
this.pack();
}
}
public class MyFrameTest {
public static void main(String[] args) {
MyMainForm frm= new MyMainForm("Calculator");
frm.setVisible(true);
}
}
【问题讨论】:
-
谢谢你,但课程运行良好,问题只出在 UI 设计器上。预览不起作用
标签: java intellij-idea