Every so often I manage to do something really silly in the GUI builder, which causes unexpected behaviour (and exceptions) when the form is actually executed. And today I realised again that it is indeed sometimes important which step you choose to associate a piece of code with. For example, accidentally trying to set a property on the component in the pre-creation step would fail since the component just doesn’t exist yet at that point.
So the tip I want to share with you today is this. If you encounter a component that does something unexpected (or doesn’t as the case may be), then start off by looking at it using the Code Customizer. It can be accessed by right-clicking on the component and choosing Customize Code…
The Code Customizer is a handy view showing you the source code related only to the current component, in the order in which it will be executed. And if you read through the code in sequence there, many errors will become very obvious indeed.
Of course, setting the text as in the above example should rather be done by setting the text property. Then the GUI builder will take care of setting it properly. This is intended just as an example of the type of issue that you could pick up in this way.
For more information about the NetBeans GUI Builder, have a look at the Introduction to GUI Building tutorial.