VisualAge provides button beans from the com.sun.java.swing and java.awt packages.
You can add a button bean to enable the user to perform an action or select a state.
Bean | Description |
---|---|
JButton (Swing) or Button (AWT) | A push button, generally used to perform a function |
JCheckBox (Swing) or Checkbox (AWT) | A setting button that is checked when selected |
JRadioButton (Swing) or CheckboxGroup (AWT) | A radio button or group for mutually exclusive settings |
JToggleButton (Swing) | A two-state push button that appears to be pushed in when selected |
Adding or customizing graphic images for Swing buttons
You can add or replace images for Swing buttons, such as JButtons and
JCheckBoxes. Specify the graphic file for one or more image properties
in the component's property sheet.
Property | Represents... |
---|---|
icon | unselected button |
pressedIcon | pressed button |
selectedIcon | selected button |
disabledIcon | unselected disabled button |
disabledSelectedIcon | selected disabled button |
rolloverIcon | unselected rollover button |
rolloverSelectedIcon | selected rollover button |
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:
getButtonGroup1.add(ivjJRadioButton1);
Adding a group of Checkboxes as radio buttons
Use a CheckboxGroup bean to define a group of radio buttons:
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.
Visual bean basics
Tearing off properties
Using VisualAge beans in visual composition
Adding the IBM Java Examples project
Button beans