The Source for Java Technology Collaboration
User: Password:



Fabrizio Giudici

Fabrizio Giudici's Blog

Good advice: buy that book

Posted by fabriziogiudici on September 19, 2007 at 06:29 AM | Comments (4)

I received my copy of "Filthy Rich Clients" by Chet Haase and Romain Guy a few days ago (now in good company with "Rich Client Programming"), but until this morning I didn't find the time to read it.

So, just after waking up, in the usual last ten minutes before getting to work, I had the idea to check whether the book could help me in fixing a problem that was around since a few days (actually I was working on it only during breaks, but you get the point). If you read my latest blog post, you know that I'm working on mixing the Visual Library with JXMapViewer from SwingLabs. The two components should be rendered one over the other, and for this kind of stuff there's JLayeredPane. Unfortunately, it didn't worked well for me, I presumed for something related to the LayoutManager. So I developed a customized LayoutManager and went for some customized code extending JPanel (quite a common (anti)pattern for people working with Swing). Yesterday I discovered that the stuff wasn't working properly on Linux (don't know if because of the different operating system or because I tested it with Java 6); more code changes followed; then I added a third layer to render the navigation controls and the stuff got completely broken. Despair: this stuff must be demoed next week, so I scheduled a "massive revert" thinking of giving up with some parts of the demo.

This morning I took the book, went to the "Layered Panes" chapter, "Layered Panes and Layouts" paragraph. Here's the illuminating excerpt:

The only efficient way to use a layout with a layered pane are to write your own or to use the least-known layout of all time, java.awt.OverlayLayout.

Yep, it was indeed the least-known of all time, I often navigate inside Java sources in search of inspiration but I always missed it! The result is that these lines work for me:

        setLayout(new OverlayLayout(this));
        add(backgroundComponent, new Integer(100));
        add(sceneComponent, new Integer(200));
        add(foregroundComponent, new Integer(300));

Got rid of the code bloat, now everything is simpler, it works everywhere, it can be demoed next week ;-) Thanks Chet and Romain!


Technorati Tags: ,






Photo courtesy of Geertjan Wielenga

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

  • Hi Fabrizio,
    thanks for the advice...I have the right side of your pic yet...now I need to complete on the left...

    Kind regards,
    Lucio

    Posted by: benfante on September 19, 2007 at 07:15 AM

  • OverlayLayout is nice, but it doesn't play well with decorated windows as shown in this entry on my blog.

    Posted by: kirillcool on September 19, 2007 at 10:33 AM

  • Hi Kirill, very interesting link, I've bookmarked it. Fortunately I don't have decorations :-) ... at least for this usage.

    Posted by: fabriziogiudici on September 19, 2007 at 11:21 AM

  • I'm going to buy that book, it certainly looks worth the read.
    Looking at the topics covered list I do notice that Filthy Rich Clients seems to be concentrating on the Filthy Rich but not much on the Client side. Does any of it discuss methods and practises for doing JPA to a remote database or accessing servers across the internet for persistence?

    Posted by: luggypm on September 20, 2007 at 12:47 AM



Only logged in users may post comments. Login Here.


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