Elegant way to add a new form instance to a Swing object

Hi,

As far as i know (please correct me if i’m wrong) the only way to display a Servoy form in a Swing or awt object (for example, the JSplitpane and JInternalFrame beans) is to add the form to a tabpanel and then add that tabpanel to the bean. Because there is no way to create a new “tabpanel instance”, it is impossible to add a newly created form instance to a Swing or awt container.

I have written my own “MDI Desktop” plugin that uses a JDesktopPane and JInternalFrame’s. It works, but at the moment i unfortunately have to use an extremely ugly method to get a new form instance in a new MDI Window: I let Servoy create a non-modal window containing the form and i then ‘steal’ the parent component out of it by literally doing a few getParent() calls on a random form element. (this is impossible from javascript but it works from a java plugin)

I think it would be great if there would be a more elegant way to do this.

Possible solutions:

  • let the form object itself behave like a java.awt.Component

  • create a form controller method that returns the Component

That is a faulty assumption.

You will have to do some searching but you can add a form just as you would when you work with a true Java app.

Either on the forum or in Servoy Magazine you should be able to find how to do it…

I have already done a lot of searching :slight_smile:

The only thing i could find about this, is this forum topic:

http://forum.servoy.com/viewtopic.php?p … e0e7bfb752

… in which pbakker suggests to use a tabpanel.

The treecontrol sample solution also uses tabpanels.

But maybe i’m not using the right search terms? Can you point me in the right direction?

hmmm, sorry :oops:

You indeed need to use a tabPanel

Hi,

It seems that you could be there with that linked thread.

I may be mistaken but if you have added your tabpanel to the bean then the tabpanel has an element name - say ‘tabs_70’

You can use the element tab functions to manipulate the tabs/forms attached to it.

Thus you have fx calls like: addTab(), removeTabAt() etc which would allow you to erase and place forms at will using Servoy native methods

So check out those functions in the method editor and / or docs

Hope this helps

Cheers
Harry

Indeed, that allows you to add form instances to an existing tabpanel that’s already in a bean.

It still doesn’t allow you to create a new form instance and to add that form instance to a new swing object, for example a freshly created JInternalFrame.

The problem is that you need a separate tabpanel for each form instance/JInternalFrame pair and there’s no way to create one programmatically.