How to programatically create a Form?

Using the Intellij UI Designer I've created a new GUI Form (JGoodies) and I am able to add this to a JTabbedPane (in another form) by selecting the "Non-Palette Component" option in the Palette. This works just fine, but what I would really like is to programatically create such a Form and add this to the JTabbedPane. The use case is as follows:

I have a form that allows me to search for customers that displays a list search results. I also have an edit customer form which allows me to edit a single customer. What I would like is to be able to create a new tab every time I click on a customer in the search results. This should create a new edit customer tab and add it to the JTabbedPane. Since Intellij usually takes care of creating the Form from its .form file, I have no way of initializing it manually - I need to be able to somehow create a swing component, which I can add to the JTabbedPane. Does anyone know how to do this? I would appreciate any help I can get.

7 comments
Comment actions Permalink

Hello migueljuan15,

Using the Intellij UI Designer I've created a new GUI Form (JGoodies)
and I am able to add this to a JTabbedPane (in another form) by
selecting the "Non-Palette Component" option in the Palette. This
works just fine, but what I would really like is to programatically
create such a Form and add this to the JTabbedPane. The use case is as
follows:

I have a form that allows me to search for customers that displays a
list search results. I also have an edit customer form which allows me
to edit a single customer. What I would like is to be able to create a
new tab every time I click on a customer in the search results. This
should create a new edit customer tab and add it to the JTabbedPane.
Since Intellij usually takes care of creating the Form from its .form
file, I have no way of initializing it manually - I need to be able to
somehow create a swing component, which I can add to the JTabbedPane.
Does anyone know how to do this? I would appreciate any help I can
get.


No, IntelliJ IDEA does not create a form from the .form file. When you bind
the form to a class, the form components are initialized when you create
an instance of this class. So you just need to bind the form to a class,
bind the top-level component of the form to a field in this class, and add
that top-level component to your JTabbedPane or any other container.

--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"


0
Comment actions Permalink

Hi Dmitry,

thanks for your quick answer. Could you please show me how I can programatically bind the form to a class and the top-level component of the form to a field in the class? I am not sure I understand how to do this - I've only ever done this through the UI Designer using the "bind to class" property. What I am ultimately aiming for is the ability to create new Forms on the fly at runtime. Many thanks!

0
Comment actions Permalink

Hello migueljuan15,

thanks for your quick answer. Could you please show me how I can
programatically bind the form to a class and the top-level component
of the form to a field in the class? I am not sure I understand how to
do this - I've only ever done this through the UI Designer using the
"bind to class" property. What I am ultimately aiming for is the
ability to create new Forms on the fly at runtime. Many thanks!


You do not need to bind the form to a class programmatically. Just do it
the usual way, and create an instance of the bound class at runtime.

--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"


0
Comment actions Permalink

Hi Dmitry,

Maybe I'm not understanding how this works, but I'd like to do something like this every time I want to create a new tab:

EditCustomerForm form = new EditCustomerForm();

and I'd like to add this to my JTabbedPane using the add method

mainTabbedPane.add(...);

Problem is, EditCustomerForm is not a swing component, so I can't add this to the tab. How can I add a bound class to a tabbed pane?

0
Comment actions Permalink

Your form has most probably a JPanel as its top component. Then create a JPanel field in your EditCustomerForm class, bind your top panel to this field, and add a getter method for it. Your code would then look something like that:

EditCustomerForm form = new EditCustomerForm();
mainTabbedPane.add(form.getMainPanel());

0
Comment actions Permalink

Hello migueljuan15,

Hi Dmitry,

Maybe I'm not understanding how this works, but I'd like to do
something like this every time I want to create a new tab:

EditCustomerForm form = new EditCustomerForm();

and I'd like to add this to my JTabbedPane using the add method

mainTabbedPane.add(...);

Problem is, EditCustomerForm is not a swing component, so I can't add
this to the tab. How can I add a bound class to a tabbed pane?


- Bind the top-level component of the form to a field in EditCustomerForm
- Create an accessor for the field: getMainPanel() for example
- mainTabbedPane.add(form.getMainPanel())

--
Dmitry Jemerov
Development Lead
JetBrains, Inc.
http://www.jetbrains.com/
"Develop with Pleasure!"


0
Comment actions Permalink

Ahhh, of course! Yes, that makes perfect sense, don't know why I didn't see it. Anyway, many thanks for you help!

0

Please sign in to leave a comment.