Customizing with BeanInfo
So far, everything NetBeans has known about our beans has
been determined by low-level reflection—that is, by looking at the methods
of our classes. The java.Beans.Introspector
class gathers information on a bean using reflection, then analyzes and
describes a bean to any tool that wants to know about it. The
introspection process works only if the class follows the JavaBeans naming
conventions for its methods; furthermore, it gives us little control over
exactly what properties and events appear in NetBeans menus. For example,
we’ve seen that NetBeans by default shows all the stuff we inherit from
the base Swing component. We can change that by creating BeanInfo classes for our beans. A BeanInfo class provides the JavaBeans
introspector with explicit information about the properties, methods, and
events of a bean; we can even use it to customize the text that appears in
menus in NetBeans (and in other IDEs).
A BeanInfo class implements the
BeanInfo interface. That’s a
complicated proposition; in most situations, the introspector’s default
behavior is reasonable. Instead of implementing the BeanInfo interface, we extend the SimpleBeanInfo class, which implements all of
BeanInfo’s methods. We can override
specific methods to provide the information we want; when we don’t
override a method, we’ll get the introspector’s default behavior.
In the next few sections, we’ll develop the DialBeanInfo class that provides explicit
information about our Dial bean.