Defining a Complex Property Editor
There is another YesNoPanel
property value that requires a
property editor. The messageText
property of YesNoPanel
can specify
a multiline message to be displayed in the panel. This property
requires a property editor because simple beanbox programs like
ShowBean
don’t distinguish between
single-line and multiline string types; the JTextField
object it uses for text input
doesn’t allow the user to enter multiple lines of text. For this
reason, we define the YesNoPanelMessageEditor
class and register
it with the PropertyDescriptor
for
the message property, as shown in Example 15-6.
Example 15-8
shows the definition of this property editor. This is a more complex
editor that supports the creation of a custom editor component and
graphical display of the value. Note that this example implements
PropertyEditor
directly, which
means that it must handle registration and notification of PropertyChangeListener
objects. getCustomEditor( )
returns an editor
component for multiline strings. Figure 15-1 shows this custom
editor within a dialog box created by the ShowBean
program. Note that the Ok button in this figure is part of the
ShowBean
dialog, not part of the
property editor itself.
The paintValue( )
method displays the value of the messageText
property. This multiline value
doesn’t typically fit in the small rectangle of screen space allowed
for the property, so paintValue( )
displays instructions for popping up the custom editor, which allows the ...
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.