Java Reference
In-Depth Information
A BeanInfo class for a bean must satisfy the following requirements:
The name of the BeanInfo class must be the name of the bean class
appended with BeanInfo. For example, if the bean class is named
Movie, its BeanInfo class must be named MovieBeanInfo.
■■
The BeanInfo class of a bean must implement the java.beans.BeanInfo
interface. Alternatively, the BeanInfo class can extend the SimpleBeanInfo
class in the java.beans package, which is a utility class that implements
the methods of the BeanInfo class for you with empty method bodies.
■■
Some of the methods in the BeanInfo interface include the following:
public int getDefaultEventIndex().
Returns the index of the event that is
most likely used by other beans.
public int getDefaultPropertyIndex(). Returns the index of the property
that is most likely used by other beans.
public Image getIcon(int kind). Returns the icon for the bean specified
by the kind argument, which is either ICON_COLOR_32x32,
ICON_COLOR_16x16, ICON_MONO_32x32, or ICON_MONO_16x16.
public EventSetDescriptor [ ] getEventSetDescriptors(). Returns an
array containing the types of events that this bean generates and their
corresponding add and remove methods.
public PropertyDescriptor [ ] getPropertyDescriptors().
Returns an
array containing the properties of this bean.
public MethodDescriptor [ ] getMethodDescriptors().
Returns an array
containing the methods of this bean.
A bean can have a BeanInfo class that does not implement all the
methods of the BeanInfo interface. For those methods in a BeanInfo class
that are not implemented, the builder tools will use introspection instead.
This allows you to use a BeanInfo class for some aspects of a bean and
have the builder tool determine other aspects of your bean.
The following MovieBeanInfo class demonstrates writing a BeanInfo class
for a bean. Study this class and try to determine what type of information it is
providing to the builder tool, versus the information about the Movie bean
that the builder tool will have to figure out by itself using introspection.
package video.store;
import java.beans.*;
Search WWH ::




Custom Search