The Source for Java Technology Collaboration
User: Password:



Scott Violet

Scott Violet's Blog

Matisse: one step closer to cross platform layout nirvana

Posted by zixle on June 10, 2005 at 11:07 AM | Comments (2)

Yow, it's been more than a month since my last blog! I intended to write a blog once a week, but, well, finishing up table sorting, JavaOne and Matisse have kept me unbelievably busy in the past month:( I'll blog later about table sorting and other Mustang goodness. In the mean time I wanted to blog about Matisse. Matisse shows work that the NetBeans and Swing teams have been deeply involved in for close to a year (YOW!) now. For those interested there is a long thread on javalobby talking about Matisse. In this blog I'll cover some of the new JDK features that make Matisse possible.

Baseline support

In visual designers paradise all components are aligned nicely along their baseline. For example, labels should be aligned along their baseline with textfields. To date this has been problematic because we haven't provided an API for getting this information, meaning lots of tricks and assumptions. Thankfully we've added this API and it's now part of Mustang. For details read an older blog on baseline layout. Matisse makes extensive use of this API to allow aligning components along their baselines. For details on the API see JComponent.getBaseline and JComponent.getBaselineResizeBehavior .

Preferred Gap

Each of the platforms (JLF, Windows, Gnome and OS X) provides guidelines as to how far apart various widgets should be placed from each other. We wanted the ability to make it easy for developers to honor these guidelines. You can see this in the Matisse demo, as the components gets close enough they snap to a location based on the guidelines of the current look and feel. The API is in the works for mustang and was discussed in a thread on the swing forums.

GroupLayout

So how does all this tie together? Yes, a new LayoutManager called GroupLayout. The LayoutManager offers the ability to align components along their baseline as well as to easily place components using the preferred gap API. GroupLayout itself is, in some ways, a combination of BoxLayout and SpringLayout. It's more constrained than SpringLayout and we are investigating moving it on top of SpringLayout. Later on I'll provide more details of GroupLayout. For those coming to JavaOne we'll cover it the layout roundup talk.

Do we really need to wait for Mustang to use this?

No! We realize it's important for developers to use this on pre 1.6, even pre 1.5 JREs. As such, we've rolled these three pieces into an open source project that runs on 1.4.2, and newer, JREs. The project is under the swing-labs umbrella and is called swing-layout. For more information, including source, head over to its home page.

Bookmark blog post: del.icio.us del.icio.us Digg Digg DZone DZone Furl Furl Reddit Reddit
Comments
Comments are listed in date ascending order (oldest first) | Post Comment


  • This looks really nice. I do a lot of layout work with swing, mostly by wrapping the low-level layout managers with specialized 'builder' classes and coding the GUI on top of that. Next chance I get I'm going to rewrite some of the builders using GroupLayout. Hopefully this will make them much cleaner and eliminate of most the pretty hacky code that I've already written to lineup baselines and vary component spacing.

    The big feature I'd like to request would support for inter-panel layouts, at least programmatically. So if you had a tabbed panel below a bunch of controls the components in the tabbed pane will lineup with the components above them.

    Posted by: abansil on June 12, 2005 at 10:35 AM

  • abansil,
    As I'm sure you know inter-panel layout is no simple task. It may be possible, but it's not high on the priority list. If you have the time check out the layout project and offer up suggestions.
    Thanks!
    -Scott

    Posted by: zixle on July 01, 2005 at 04:35 PM





Powered by
Movable Type 3.01D
 Feed java.net RSS Feeds