Thursday, February 21, 2008

Automatically Generated JTabbedPane

Update: the APIs shown in this blog entry have changed slightly in newer releases of Metawidget. Specifically .setParameter has been replaced with a more typesafe mechanism. Please download the latest documentation from

The new release of Metawidget adds support for automatically generated JTabbedPanes to TableGridBagLayout. This is in response to a forum posting by Mark P Ashworth (thanks Mark!).

To take the Swing Address Book from the tutorial as an example, if you have... setting a single parameter on the Metawidget...

  TableGridBagLayout.SECTION_AS_TAB );'ll now get...

...note the Contact Details and Other sections are now arranged in a JTabbedPane.


Mark Ashworth said...


The tab panel supports looks exactly like how I imagined, thanks.

Mark P Ashworth

Mark Ashworth said...

A nice feature would be if you choose which objects get added to the JTabbedPane.

For example:

String name;
Address address;
List contacts
List sites;

Now, the name and address field would be nice underneath each other but the contacts and sites in the JTabbedPane.

Maybe it would be possible to add the information in the introspect sources, for example the XML one could as follows:

<entity type="Client">
<property name="name">
<property name="address">
<property name="contacts" group="tabbedpane" />
<property name="sites" group="tabbedpane" />

Just a thought.

Richard said...


That's pretty much how it works. You don't say 'tabbedpane' as such (that would be a bit too Swing specific) but you say 'I want this property in section x'...

<entity type="Client">
<property name="name">
<property name="address">
<property name="contacts" section="tab 1" />
<property name="sites" section="tab 2" />

...and then you say to the Layout 'render the sections as tabs'.

Anyway, you should be able to try it for yourself later today.