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 http://metawidget.org

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...


...by setting a single parameter on the Metawidget...

m_metawidget.setParameter(
  "sectionStyle",
  TableGridBagLayout.SECTION_AS_TAB );

...you'll now get...


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

3 comments:

Mark Ashworth said...

Hi,

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

Regards,
Mark P Ashworth
javameme@gmail.com

Mark Ashworth said...

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

For example:

Client
------
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" />
</entity>

Just a thought.

Richard said...

Mark,

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" />
</entity>

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

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