Skip to main content

Making your components work nicer inside Matisse

Posted by mister__m on February 20, 2008 at 7:20 AM PST

A co-worker had been developing some nice-looking custom components for a customer project. It was tightly integrated with the backend logic, though, so he tried to use it with Matisse, there were several issues, from class loading errors to slowness, since the component was trying to do its "real task" inside the designer.

So, when he told me that, I immediately recalled a trick I came to know way back in 1999, while I was struggling with Java and Swing for the first time. The java.beans package comes with a class named Beans that comes with a bunch of static utility methods. One of them, isDesignTime(), let your component find out if it's being used in preview mode.

He changed the component constructor to check for design time and skip the "black magic" section. It worked like a charm and he said it was the best tip I gave him last year. So now I've finally had the time to blog again, I thought it would be an interesting tip to share :-)

Related Topics >>

Comments

the bug has been set to won't fix because it was not possible to load the Beans class in its own classloader

second try ;-)
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6669869

I would not recommend this as best practice. Remember the matisse module sets Beans.setDesignTime(true) when it is loaded and this flag may be read from other modules too.

Just use this trick if you are sure your GUI component will never be used _inside the IDE since it will think it is in design time....

this flag causes us with the NetBeans OpenGL Pack (JOGL components) a lot of problems ;-)

https://netbeans-opengl-pack.dev.java.net/

(but this could be probably solved if matisse would load the Beans class in its own classloader...)

I've filed a issue for it at http://www.netbeans.org/issues/show_bug.cgi?id=127935.

Regards.