
The easiest way to assign a description to a component is to give it a tooltip. This
way, your accessibility information also serves as context-sensitive help for novice
users:
continue.setToolTipText("Click here to continue");
If, for some reason, you want to assign an accessible description to a component
without giving it a tooltip, you can use code like this:
continue.getAccessibleContext().setAccessibleDescription("Continue button");
It is also helpful to assistive technologies if you provide names for your various
components. A name should be a short human-readable string that uniquely iden-
tifies the component, at least within the current window or dialog box. Buttons,
labels, menu items, and other components that display labels simply use those
labels as their accessible names. Other components need to have names assigned.
Her e is one way to do that:
JTextField zipcode = new JTextField();
zipcode.getAccessibleContext().setAccessibleName("zipcode");
In a GUI, important components that do not display their own labels are often
associated with
JLabel components that serve to identify them. When this is the
case, you can use the
setLabelFor() method of JLabel to set the accessible name
of the other component. The code might look like this:
JLabel zipcodeLabel = new JLabel("Zipcode");
JTextField zipcode = new JTextField();
zipcodeLabel.setLabelFor(zipcode);
By taking the simple step of assigning ...