Skip to main content

Label components

Java™ checkpoint 2.4

Associate labels with controls, objects, and icons.

 

Rationale

Labels name an object (e.g., icon names, window titles, button labels, edit fields). The labels must be associated programmatically with the object in order for the assistive technology to make them available to the user. If the labels are not associated programmatically, screen readers may use proximity to determine the label for a control or object. Proximity is not an accurate way to determine object labels.

Development techniques

One of the following techniques is the minimum required to meet Checkpoint 2.4 from the IBM Java Accessibility Checklist:

// 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));
AccessibleRelationSet abuttonRelationSet =
  aButton.getAccessibleContext().getAccessibleRelationSet();
  abuttonRelationSet.add(new AccessibleRelation
  (AccessibleRelation.LABELED_BY, myLabel));
//Rest of the application...

Testing techniques

Test the software to ensure that it complies with accessibility requirements.

Tools

You will need to install the following tools to test this checkpoint:

Windows techniques

The following techniques are required to verify this checkpoint:
  Action Result
1 Test labels with a screen reader.

Pass:

The screen reader reads the object or control and the text label associated with it. Both the type of control and the visible label for the control must be read to pass the test. If there is no visible text label, none will be read by the screen reader.

Fail:

The screen reader reads the input field, but not the text label. For example, tab to an input field labeled "Name". If the screen reader only says "edit" and does not read the label "Name", it is not accessible.Since some techniques such as AccessibleRelation are not supported through the Java Access Bridge, perform the next test to see if the problem is the application or the screen reader.
2 If the screen reader did not read the text labels, run JavaFerret to determine if this is a problem with the application or the screen reader.

Pass:


Fail:

JavaFerret displays the name of the object, but not the label associated with it. If the screen reader did not read the label and JavaFerret does not display the label, it is not accessible.


©2001, 2008 IBM Corporation

Last updated February 15, 2008.