Java Technology Home Page
A-Z Index

Java Developer Connection(SM)
Online Training

Downloads, APIs, Documentation
Java Developer Connection
Tutorials, Tech Articles, Training
Online Support
Community Discussion
News & Events from Everywhere
Products from Everywhere
How Java Technology is Used Worldwide
 
Training Index

Introduction to the JavaBeans API, Magercise 8
Exploring Bean Customization: FlexLabel

by John Zukowski, MageLang Institute

[Help | API Docs | Short Course | Magercises]

This Magercise explores FlexLabel, a freeware graphical label Bean, to demonstrate the range of customization opportunities provided by the JavaBeansTM framework. FlexLabel demonstrates a customization dialog as well as several property editors. In addition, FlexLabel addresses the general issue of working with Beans that include nonserializable "components."

This Magercise requires you to have already completed the prerequisites, or by some other means be quite familiar with building JAR files for Beans, loading JAR files into your IDE or the BeanBox, and all related activities.

Magercise 8 Prerequisites

Tasks

  1. The first step is to start up an IDE or the BDK's BeanBox to explore FlexLabel.

  2. Next, save FlexLabel's solution files to a working directory and build FlexLabel, being careful not to omit any of the files. (There are no skeleton files--everything is on the solution page.)

  3. Next, load the FlexLabel Bean, instantiate the Bean, and experiment with its properties.

  4. Next, explore the editing facility for the label property. Recall that the StickFigure-related Magercises use the JavaBeans framework to register discrete-valued properties for display in a drop-down list, as does FlexLabel for alignment and imagePosition.

    FlexLabel, however, also illustrates a custom property editor; that is, an editor that's implemented in a custom panel. Note that FlexLabel provides the mechanics for painting the "Edit Label..." prompt, much like the prompt that's painted for the font property. If you haven't already done so, activate the custom label editor.

    Investigate the JavaTM source files that implement and register the custom editor: FlexLabelBeanInfo.java, LabelEditor.java, and LabelTextAreaPanel.java. Note that LabelEditor specializes java.beans.PropertyEditorSupport. Investigate the methods for this class that were not used in the StickFigure Magercises, but that are required for implementing a custom editor, in particular,

    • isPaintable()
    • paintValue()
    • supportsCustomEditor()
    • getCustomEditor()

    Note that getCustomEditor() provides the link/connection between the JavaBeans framework and LabelTextAreaPanel, which implements the graphical panel for the editor. (Recall that FlexLabelBeanInfo associates a property editor class, in this case, LabelEditor, with the label property.)

  5. FlexLabel supports an image via a file specification. Investigate the image processing-related methods in FlexLabel.java, as well as the image-related properties and the customization dialog. How might you support images differently (perhaps, without using a file specification)? Do you think that a file specification/association is even appropriate? If not, how would you handle an Image instance directly, considering issues such as the need for FlexLabel to be serializable?

    Programmatically, one approach to associating an image with a FlexLabel instance would be to create an Image object and pass it as an argument to a FlexLabel constructor, or dynamically specify the image via an access method. FlexLabel supports these operations. But, is it appropriate to design an image-related property that manipulates Image instances at design time? If an Image instance is created as an instance variable in FlexLabel, is FlexLabel serializable?

Where help exists, the task numbers above are linked to the step-by-step help page.

Solution Source

Demonstration

After loading the FlexLabel Bean, it should appear in the palette:

FlexLabelBeanInfo provides icons; note the icon appearing in the palette.

From the palette you can select FlexLabel and instantiate it on the worksheet:

The FlexLabel instance will appear with a default label and no image, which you can configure from the BeanBox.

FlexLabel provides several custom property editors, which are displayed in the BeanBox's property sheet when you instantiate and then select a FlexLabel instance:

Note that FlexLabel provides drop-down lists for the alignment and imagePosition properties. It also takes advantage of the built-in property editors for the horizontalSpace and imageFile properties, and inherits the superclass property editors for background, foreground, and font.

In contrast to the drop-down lists for alignment and imagePosition, FlexLabel provides a custom property editor for label. For the property sheet, FlexLabel provides a custom graphic that paints the string "Edit Label..." adjacent to the label for label. Clicking over this graphic activates the custom property editor:

Lastly, FlexLabel collects together the principal image- and text-related customization properties in a separate customization panel, which most IDEs display in a separate window:

Magercise 9
Short Course
About This Short Course

Copyright © 1998-1999 MageLang Institute. All Rights Reserved.


[ This page was updated: 27-Oct-99 ]

Products & APIs | Developer Connection | Docs & Training | Online Support
Community Discussion | Industry News | Solutions Marketplace | Case Studies
Glossary - Applets - Tutorial - Employment - Business & Licensing - Java Store - Java in the Real World
FAQ | Feedback | Map | A-Z Index
For more information on Java technology
and other software from Sun Microsystems, call:
(800) 786-7638
Outside the U.S. and Canada, dial your country's AT&T Direct Access Number first.
Sun Microsystems, Inc.
Copyright © 1995-99 Sun Microsystems, Inc.
All Rights Reserved. Legal Terms. Privacy Policy.