VisualAge provides button beans from the
com.sun.java.swing and
java.awt packages. Although Swing and AWT beans can
be mixed, it is inadvisable.
You can add a button bean to enable the user to perform an action or select
a state.
- Add one of the following button beans:
- Define initial characteristics of the button component.
- Defining a button label
- Enter text for the text or label property in the
component's property sheet.
- Adding or customizing graphic images for Swing buttons
- You can add images or replace default images. For example, you can
add graphics to a JButton or change the default images of a JCheckBox.
Select or specify a graphic file for one or more image properties in the
component's property sheet.
- icon represents an unselected button
- pressedIcon represents a button that is pressed
- selectedIcon represents a selected button
- disabledIcon represents an unselected button that is disabled
- disabledSelectedIcon represents a selected button that is
disabled
- rolloverIcon represents an unselected rollover button
- rolloverSelectedIcon represents a selected rollover button
- Defining tool tip text for a button component
- For Swing components, you can specify tool tip text, also known as
fly-over text or hover help. Enter text for the toolTipText
property in the component's property sheet.
- Defining initial availability
- By default, the component is initially enabled for user
interaction. To initially disable the component, set the
enabled property to False in the component's
property sheet.
- Defining the initial state of a toggle component
- Set the selection or state property in the
component's property sheet. For initial selection, set the
property value to True. Otherwise, the value should be
False. If the component is one of a group of mutually
exclusive choices, only one member of the group should be initially
selected.
- If applicable, assign a toggle component to a group of mutually exclusive
choices. Only one member of the group can be selected at a time.
- Adding a group of JToggleButton or JRadioButton beans
- Use a ButtonGroup to define a group of buttons:
- Add the buttons for the group.
- Add a ButtonGroup bean to the free-form surface.
- Save the composite bean.
- On the Methods page, add user code in the get method of each button to add
the button to the button group. For example, to add JRadioButton1 to
ButtonGroup1, add this code to the getJRadioButton1()
method:
getButtonGroup1.add(ivjJRadioButton1);
- Adding a group of Checkboxes as radio buttons
- Use a CheckboxGroup bean to define a group of radio buttons:
- Add the check boxes for the group.
- Add a CheckboxGroup bean to the free-form surface.
- In the property sheet of each Checkbox bean, specify the get method of the
CheckboxGroup for the checkboxGroup property. For example,
to add Checkbox to CheckboxGroup1, specify
getCheckboxGroup1() for the checkboxGroup
property.
- Provide runtime logic for the button component.
- Calling a method when a button is selected
- Connect the button's
actionPerformed(java.awt.event.ActionEvent)
event to the method on the target bean.
- Obtaining the selected choice from a group
- From the group's popup menu, tear off the property that represents
the selected choice. For a ButtonGroup, tear off the
selection property. For a CheckboxGroup, tear off the
selectedCheckbox property. After tearing off the property,
you can make connections to features of the Variable that represents the
selected choice property.
- Disabling a button
- Connect a related event to the button's enabled property
and set the connection parameter value to False.
- Enabling a button
- Connect a related event to the button's enabled property
and set the connection parameter value to True.
For examples, see the ToDoList class in the
com.ibm.ivj.examples.vc.todolist
package, and the JRadioButtonPanel and RadioButtonPanel
classes in the
com.ibm.ivj.examples.vc.utilitybeans
package. These examples are shipped in the IBM Java Examples
project.
Working with Beans Visually
Tearing Off Properties
Using VisualAge Beans in Visual Composition
Adding the IBM Java Examples project
Button Beans
