Adding a Custom JavaBeans Component

You can now add components to the LookandFeel form created in the previous section. You start by adding and customizing a JavaBeans component. (JavaBeans components are referred to simply as beans.)

You will not find this bean in the Component Palette. It was developed specifically for this tutorial and it must be added using the Explorer window. (Later in this tutorial you will learn how to add this bean to the Component Palette, making it as easily accessible as the standard user interface components.)

Tip:If the Explorer window is not open, choose View Explorer. You can use the View menu to open any window at any time.

To add the bean:

  1. Switch to selection mode in the Component Palette.

    In selection mode you can easily add components to a form by selecting an item in the Component Palette, then clicking the form where it is to be placed. The arrow icon is selected (as shown below) when selection mode is active.

  2. Selection Mode
  3. Locate the RadioButtonGroupPanel bean in the Explorer window by expanding the tutorial node, then the lookandfeel node, then the radiobuttongroup node.

    The bean's package name, tutorial.lookandfeel.radiobuttongroup, corresponds to this directory structure.

  4. Right-click the RadioButtonGroupPanel bean in the Explorer window and choose Copy from the contextual menu.

    Be sure to right-click the bean node, RadioButtonGroupPanel, not the directory node, radiobuttongroup.

  5. Right-click anywhere on the LookandFeel form in the Form Editor window and choose Paste from the contextual menu.

    The Component Inspector now includes a node named radioButtonGroupPanel1 for the RadioButtonPanelGroup bean. The form updates to display the bean.

  6. Right-click the radioButtonGroupPanel1 node and choose rename from the contextual menu. Type lnfSelector in the text field. (lnf is short for look and feel.) Click OK.

To customize the bean:

  1. Select the lnfSelector node in the Component Inspector.

    The Properties tab is selected (by default) and some of the bean's properties are listed in the left column.

  2. Select the Other Properties tab.

  3. Select buttonLabels from the list of properties, then click the ellipsis button.

    A property editor opens.

  4. Click the Form Connection tab.

  5. Select the User Code radio button and type the following Java statement into the text area.
    new String[] {"Java", "Microsoft Windows", "CDE"}
    
    This statement initializes an array of strings and each string must be quoted. After typing the statement, click OK.

  6. Select selection from the list of properties, then click the ellipsis button.

    A property editor opens.

  7. Type the label of the initially selected radio button (either Java, or Microsoft Windows, or CDE) into the text field. (Notice that there are no quotes.) Click OK.

    If the selection property is not set in the property editor, the first label added determines the initial selection. Since the Java label was added first, the default initial selection is the Java button.

  8. Select groupLabel from the list of properties, then click the ellipsis button.

    A property editor opens.

  9. Type Look and Feel Selector, then click OK.

    The form updates to display the new border title.

Next:Adding Swing Components
Back:Creating a Container

Legal Notices