简体   繁体   English

如何使用在 IntelliJ IDEA 中创建的 GUI 表单

[英]How to use GUI form created in IntelliJ IDEA

I'm creating a simple GUI form with one button in IntelliJ IDEA 9. The class which was created with the form is not JFrame or any other swing class. How I can call my form in my source code?我正在使用 IntelliJ IDEA 9 中的一个按钮创建一个简单的 GUI 表单。使用该表单创建的 class 不是 JFrame 或任何其他 swing class。如何在我的源代码中调用我的表单?

I was stumped when IntelliJ consistently errored out when choosing Form main() from the insert menu, with an error message saying something about an invalid root component.当 IntelliJ 从插入菜单中选择Form main()时始终出错时,我被难住了,错误消息说明了无效的根组件。

It turns out it means that the JPanel that is the main (root) component of your Form needs to have a field bound to it, and by default it doesn't do this.事实证明,这意味着作为Form的主要(根)组件的JPanel需要绑定一个字段,默认情况下它不会这样做。

Simply select the JPanel in the form designer, and give it a name ( field name ) in the property pane.只需在表单设计器中选择JPanel ,并在属性窗格中为其命名( field name )。

After this it will generate the main() just fine.在此之后,它将生成main()就好了。

Simply go into the class associated with your form, press alt + insert and choose "Form main()".只需进入与您的表单关联的类,按alt +插入并选择“Form main()”。


Resources :资源:

First add private JPanel Main;首先添加private JPanel Main; inside the class. Then, in the form's panel properties, add Main to the field name.在 class 中。然后,在表单的面板属性中,将Main添加到字段名称中。 Then, go to your class and from the Alt + Insert menu, select Main .然后,go 到您的 class,然后从Alt + Insert菜单,select Main

Now, the error wont come.现在,错误不会来了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM