Dmitriy
Dmitriy

Reputation: 381

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?

Upvotes: 37

Views: 43982

Answers (3)

CrudeJoe
CrudeJoe

Reputation: 11

First add private JPanel Main; inside the class. Then, in the form's panel properties, add Main to the field name. Then, go to your class and from the Alt + Insert menu, select Main.

Now, the error wont come.

Upvotes: 1

Colin Hebert
Colin Hebert

Reputation: 93197

Simply go into the class associated with your form, press alt + insert and choose "Form main()".


Resources :

Upvotes: 40

rem
rem

Reputation: 1388

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.

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.

Simply select the JPanel in the form designer, and give it a name (field name) in the property pane.

After this it will generate the main() just fine.

Upvotes: 105

Related Questions