Specifying Bean Information
The YesNoPanel
class
itself, as well as the MultiLineLabel
, Alignment
, AnswerEvent
, and AnswerListener
classes it relies on, are all
a required part of our bean. When an application that uses the bean is
shipped, it has to include all five class files. There are other kinds
of classes, however, that are often bundled with a bean but not
intended for use by the application developer. These classes are used
at “design time” by the beanbox tool that manipulates the bean. The
bean class itself doesn’t refer to any of these auxiliary beanbox
classes, so it is not dependent on them, and they don’t have to be
shipped with the bean in finished products.
The first of these optional, auxiliary classes is a
BeanInfo
class. As explained
earlier, a beanbox discovers the properties, events, and methods
exported by a bean through introspection based on the Java Reflection
API. A bean developer who wants to provide additional information
about a bean, or refine the (somewhat rough) information available
through introspection, should define a class that implements the
BeanInfo
interface to provide that
information. The ShowBean
class,
for example, uses the short descriptions it obtained through a
BeanInfo
as tooltips in its
Properties menu.
A BeanInfo
class typically
subclasses SimpleBeanInfo
, which
provides a no-op implementation of the BeanInfo
interface. When you want to
override only one or two methods, it is easier to subclass SimpleBeanInfo
than to implement BeanInfo ...
Get Java Examples in a Nutshell, 3rd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.