Download NetBeans!

20070228 Wednesday February 28, 2007

About Those Blue Blocks...

There's a school of thought that sporadically raises its head to complain about the NetBeans "blue blocks", i.e., the guarded blocks that contain the generated code provided by the "Matisse" GUI Builder. Especially those that want maximum control over their code tend to get a bit worried, justifiably, that they can't fiddle and tweak with what is, after all, their very own code.

Not everyone seems to know that it has always been possible to do so, however. You can select any Swing component in the GUI Builder, open the Properties window, and then open the Code tab. In there, you'll find 'properties' like "Pre-Init Code" and "Post-Init Code". When you click the elipsis, you get a full-blown albeit small Java editor (e.g., including code completion and syntax highlighting). There you can add initialization code, creation code, and so on. Admittedly, this is still not ideal. It's a bit cumbersome and odd to add bits of code like that. And there are many places in the code that are not covered by these 'properties'. Well, the first bit of good news is that in 6.0, there are about twice as many of these 'properties'. For example , "Pre-Declaration" and "Post-Listeners". However, as in 5.5 and before, you need to do a bit of trial-and-error to see where the code you specify as one of these properties ends up.

So... how cool would it be if you could right-click a Swing component and then choose "Customize Code". You'd then get all the code related to the Swing component and then you'd be able to edit it all and click OK in the knowledge that it would be safely integrated into the blue block? Well...

The above dialog appears when you right-click on a Swing component in the GUI Builder (in NetBeans IDE 6.0 Milestone 6, and probably before that milestone, and probably definitely after that milestone) and choose "Customize Code". There's all sorts of code and settings that you can specify for the entire Swing component, all in one place.

This is unlikely to satisfy the hard-core blue block haters. However, it is clear that this new dialog is a response to the oft-heard unhappiness around this aspect of the NetBeans GUI Builder. At the very least you've got to admit that this is a pretty strong compromise. You're still not able to tinker with the entire piece of generated code. However, you are able to tinker with all the code relevant to specific Swing components. It's worth your while to play with this for a bit and see how it works for you. You'll be surprised how far you can get with this, in terms of controlling the code that the IDE generates for you.

And, finally, it makes sense that there are some limits to this. If you were going to completely wreck your source code, how would the GUI Builder be able to deal with that? At the very least, you can always be sure that the source and the design view are in sync, because the generated code is guarded. But, as you can see, you'll be given a lot more room to manoeuvre within these constraints than before.

Feb 28 2007, 06:17:12 AM PST Permalink