Making your components work nicer inside Matisse
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 :-)
- Login or register to post comments
- Printer-friendly version
- mister__m's blog
- 1048 reads






Comments
by mbien - 2008-02-26 09:09
the bug has been set to won't fix because it was not possible to load the Beans class in its own classloaderby mbien - 2008-03-02 07:18
second try ;-)http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6669869
by mbien - 2008-02-20 12:00
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...)
by hmichel - 2008-02-20 12:40
I've filed a issue for it at http://www.netbeans.org/issues/show_bug.cgi?id=127935.Regards.