Set the focus.
Rationale
Even if the software provides keyboard access so users can navigate the software, that isn't enough if you don't know where you are. Keyboard users must be able to see the current focus point to know what to do. Imagine typing if you could not see the caret (insertion bar). Assistive technology (e.g., screen reader, screen magnifier) needs to know the position and contents of the visual focus indicator, so it can describe, magnify or manipulate the object for the user.
When editing, the caret or insertion bar is the visual focus. As a blind user moves the focus with the arrow keys, a screen reader must know the position of that focus so that it can echo the current character, word or line. Similarly, as a user tabs around a dialog, a screen magnifier needs to follow the visual focus.
Development techniques
The following technique is the minimum required to meet Checkpoint 2.2 from the IBM Java Accessibility Checklist:
- The standard method to request the focus in the JFC is to have a particular component execute the java.awt.Component requestFocus method. In most cases, this is done automatically for you in JFC by providing keyboard access. See section 2.1 Making your Application Keyboard Accessible in the IBM Guidelines for Writing Accessible Applications Using 100% Pure Java and the following sample JRequestFocusSample
- JFC might not automatically request the focus when your Java application becomes the active window. This occurs when the user is running another application and clicks on your Java application with the mouse, or presses Alt+Tab to switch to your Java application. When this happens, your application becomes "active", but an object within the application may not necessarily receive the focus. You must create a "default focus" of your own choosing, using the JFC FocusManager (javax.swing.FocusManager).
Testing techniques
Test the software to ensure that it complies with accessibility requirements.
Tools
You will need to install one of the following tools to test this checkpoint:
- A screen reader that supports Java, and the Java Access Bridge (link resides outside of ibm.com)
- One of the Java testing tools such as JavaFerret (link resides outside of ibm.com) from Sun.
Windows techniques
| Action | Result | |
|---|---|---|
| 1 | Test with the keyboard to verify there is a visible focus indicator. Tab or arrow to interactive objects on the screen (e.g., links, menus, buttons, checkboxes). Verify that you can visually identify the object that has focus. This test can be combined with the screen reader or screen magnifier test. | Pass: Visual focus may be indicated by a variety of ways including highlighting, focus rectangles and a visible insertion caret. Fail:
|
| 2 | Switch focus between several applications including Java and non Java applications.
Verify the focus is visible.
This test can be combined with the screen reader or screen magnifier test. |
Pass: Visual focus is still provided after you switch back and forth between applications. Focus may be indicated by a variety of ways including highlighting, focus rectangles and a visible insertion caret. Fail: Focus is lost when you switch back to the Java application. |
| 3 | Test with a screen reader or a screen magnifier to verify that input focus is exposed programmatically.
|
Pass:
Fail:
|
©2001, 2008 IBM Corporation
Last updated February 15, 2008.
