Software checklist

Checkpoint 2.3: Labels - examples for Java developers

Associate labels with controls, objects, icons, and images. If an image is used to identify programmatic elements, the meaning of the image must be consistent throughout the application.

This page provides specific examples to implement the Software techniques for providing labels using Java Swing. For an explanation of this requirement, see Rationale for labels in the Software checklist.


Required development techniques

The following techniques are the minimum required to meet Checkpoint 2.3 from the IBM Software Accessibility Checklist:

  1. Labels must be associated with all user controls, objects, window titles, icons and images.
  2. All images, that are not decorative and have meaning, must be used consistently through the application.

 

Examples for Java developers

1. Labels must be associated with all user controls, objects, window titles, icons and images.

Example 1

When using JFC JLabel to label another component, call the setLabelFor method to set the component it is labeling. When you use setLabelFor method, the component you label (e.g. a JTextField ) will get the AccessibleName and AccessibleDescription of the JLabel .

// Create label and explicitly set AccessibleName JLabel myLabel = new JLabel("A column of buttons"); // Create buttons JButton aButton = new JButton("Button A"); aButton.getAccessibleContext().setAccessibleName("Button A"); JButton bButton = new JButton("Button B"); bButton.getAccessibleContext().setAccessibleName("Button B"); JButton cButton = new JButton("Button C"); cButton.getAccessibleContext().setAccessibleName("Button C"); // Create a LABELED_BY relationship //that indicates that "myLabel" //is the label for "aButton" AccessibleRelationSet labelRelationSet = myLabel.getAccessibleContext().getAccessibleRelationSet(); labelRelationSet.add (new AccessibleRelation(AccessibleRelation.LABEL_FOR, aButton)); //The JLabel.setLabelFor() method as a handy shortcut to set the LABEL_FOR relationship between a label and the object that it's labeling. AccessibleRelationSet abuttonRelationSet = aButton.getAccessibleContext().getAccessibleRelationSet(); abuttonRelationSet.add (new AccessibleRelation(AccessibleRelation.LABELED_BY, myLabel)); //Rest of the application...

Example 2

Applications written for Java 1.3 or later can also support accessible relationships defined in the AccessibleRelation class. For example, you can define an AccessibleRelation of AccessibleRelation.LABEL_FOR to define a label for a specific component. This would be followed by adding an AccessibleRelation.LABELED_BY for the target component.

2. All images, that are not decorative and have meaning, must be used consistently through the application.

Example 3

When bitmap images are used to identify controls, status indicators or other programmatic elements, the meaning assigned to those images must be consistent throughout an application. See the following samples that illustrate some of these techniques: JAccessibleNameSample and JIconSample.

 

Required test techniques

Test the software to ensure it complies with accessibility requirements.

Required test software

Install the following software to test this checkpoint.

Test techniques

There are no unique steps for testing this checkpoint. Follow the required test techniques in Software checkpoint 2.3.


Debug techniques

If the screen reader test fails for any user interface element, the problem must be debugged with an accessibility API validation tool. These techniques can be used to help determine if a problem is caused by a coding error in the application, or if it is caused by a screen reader defect.


The following techniques are required to verify this checkpoint:
Action Results for compliance
  1. Review the development techniques and insure the implementation is correct according to the development techniques.
  2. Use the API validation tool that is appropriate to your product to determine if the development techniques have been implemented properly.

Additional information on how to use the API validation tool is included with the tool.

  1. The implementation is correct according to the development techniques.
  2. The accessibility API validation tool shows that the API properties expose sufficient information as defined in the development techniques for this checkpoint.
  3. Additional instructions:

©2013 IBM Corporation

Last updated January 1, 2013.