5

I have to build multiple Swing forms and I thought to speed up the process by using the Form Designer provided by Intellij IDEA.

First of all, I've created a new GUI form. Create a new gui form

Then I added some labels, text fields and a button to the form. Content

Now I want to add this form to another Panel. I've been checking out the Intellij help and I found this. Unfortunately it doesn't work like this. There is no accessible contentPane in this class, which is generated by the IDE.

What magic do I have to apply to get this to work?

Bonus question: Usually I extend a Swing component. For example in that case I would have something like public class BullshitForm extends JPanel{}. Is this possible with the Intellij Designer?

Robin
  • 8,162
  • 7
  • 56
  • 101
  • `panel1` is your `contentPane` – Meo May 17 '16 at 09:13
  • `panel1` never gets initialized. – Robin May 17 '16 at 09:21
  • And does preview work? https://www.jetbrains.com/help/idea/2016.1/previewing-forms.html – Meo May 17 '16 at 09:44
  • Yes, the preview works: https://i.imgur.com/MLNdqA5.png – Robin May 17 '16 at 10:48
  • 1
    How do you compile and run it? What is the error? You need a plugin for gradle and maven, so that the compiled form's .class file has `this.$$$setupUI$$$()`; in constructor. – Meo May 17 '16 at 11:24
  • I use Gradle, but I use the `idea` plugin. The stuff from the designer just never gets initialized. Maybe I need another plugin? – Robin May 17 '16 at 16:01
  • I know how to make it work with maven, but not sure if the plugin can be used with gradle http://stackoverflow.com/a/25877166/685796 But if you compile and run the program by IntelliJ, then it should just work anyway... – Meo May 17 '16 at 16:17
  • Unfortunately the form_rt.jar in maven central is very old. I think there is no acceptable solution for this at the moment. Thank you for finding the root of the problem! – Robin May 17 '16 at 16:20
  • you can copy that lib from IntelliJ and have it in the project – Meo May 17 '16 at 16:22

2 Answers2

2

Select the class BullshitForm press ALT + Insert and select Form main().

karoluS
  • 2,980
  • 2
  • 23
  • 44
  • This does not work when call from other class, the main form class is not initialized when main class is initialized: `contentPane cannot be set to null.`. – e-info128 Apr 04 '21 at 00:43
0

i have the exact same problem as you. I found out that the problem is that i used gradle to build my project. After the switch to maven, everythings working now.

It seems that the gradle build process did not implement the initialication of the gui controls.

Dharman
  • 30,962
  • 25
  • 85
  • 135