JDK-7179482 : Component.accessibleContext and JComponent.accessibleContext refactoring
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.accessibility
  • Affected Version: 8
  • Priority: P2
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2012-06-25
  • Updated: 2017-05-17
  • Resolved: 2013-01-31
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
8 b77Fixed
Related Reports
Relates :  
Relates :  
Both Component and JComponent have field "accessibleContext". In Component is't package private and accessed by other classes from java.awt, but in JComponent it's protected (and therefore this field hides the field from superclass). It should be refactored to a single field, which is protected in Component.

For the release notes: Note that javax.swing.JComponent.accessibleFocusHandler is deprecated. It duplicates the functionality of a field in the java.awt.Container.AccessibleAWTContainer superclass. Developers should use the java.awt.Component.AccessibleAWTComponent.accessibleAWTFocusHandler field instead.

EVALUATION After refactoring, the following code should still work: public class MyJComponent extends JComponent { public MyJComponent() { super(); accessibleContext = new AccessibleJComponent() { { accessibleContainerHandler = new AccessibleContainerHandler() { @Override public void componentAdded(ContainerEvent e) { super.componentAdded(e); doSometing() } @Override public void componentRemoved(ContainerEvent e) { super.componentRemoved(e); doSometing() } }; }; // the same for AccessibleFocusHandler } } Regardless of whether component developer extends from Component/Container (and use AccessibleComponent/Container) or from JComponent (and use AccessibleJComponent), all the methods: componentAdded(), componentRemoved(), focusGained(), focusLost(), etc. should still be called.

EVALUATION I've also noticed another related problem. Here is the code in Container, AccessibleAWTContainer inner class; public void addPropertyChangeListener(PropertyChangeListener listener) { if (accessibleContainerHandler == null) { accessibleContainerHandler = new AccessibleContainerHandler(); Container.this.addContainerListener(accessibleContainerHandler); } super.addPropertyChangeListener(listener); } It will not work in the code above: custom components will have to manually add their own AccessibleAWTContainer.AccessibleContainerHandler objects as container listeners, which is violation of AccessibleContainerHandler specification (which says that this class notifies all the registered PropertyChange listeners, when container's children are added or removed).