On Mon, 27 Apr 2026 23:04:18 GMT, Jeremy Wood <[email protected]> wrote:

>>>I guess the accessibleContext is tied to the type of the document, so if the 
>>>document is changed the accessibleContext should be updated/reset as well, 
>>>correct?
>> 
>> How the "JEditorPane.getAccessibleContext" is updated if the editorKit 
>> and/or document was updated? How we will swap 
>> AccessibleJEditorPaneHTML/AccessibleJEditorPane based on editorKit and clean 
>> all that listeners?
>
>> How the "JEditorPane.getAccessibleContext" is updated if the editorKit 
>> and/or document was updated?
> 
> Each call to `JEditorPane.getAccessibleContext()` may update the current 
> accessibleContext field. This method reads:
> 
> 
> public AccessibleContext getAccessibleContext() {
>         if (getEditorKit() instanceof HTMLEditorKit) {
>             if (accessibleContext == null || accessibleContext.getClass() !=
>                     AccessibleJEditorPaneHTML.class) {
>                 accessibleContext = new AccessibleJEditorPaneHTML();
>             }
>         } else if (accessibleContext == null || accessibleContext.getClass() 
> !=
>                        AccessibleJEditorPane.class) {
>             accessibleContext = new AccessibleJEditorPane();
>         }
>         return accessibleContext;
>     }
> 
> 
> When it replaces the old `accessibleContext` there is no observable event or 
> uninstall method. It's just discarded.
> 
>> How we will swap AccessibleJEditorPaneHTML/AccessibleJEditorPane based on 
>> editorKit and clean all that listeners?
> 
> This PR is not attempting to clean *all* the listeners. I would love it if we 
> had a `AccessibleJEditorPane.uninstall()` method, but that feels like scope 
> creep given the original complaint this PR is trying to resolve.
> 
> This PR currently caches the `JEditorPaneAccessibleHypertextSupport` as a 
> client property in the JComponent. That way if AccessibleContext X is 
> replaced by AccessibleContext Y: it will continue using the same 
> JEditorPaneAccessibleHypertextSupport.
> 
> We check make sure the hypertext support object is still relevant, and we 
> discard it if it is outdated (and remove its DocumentListener):
> 
> if (axText != null && axText.doc != getDocument()) {
>     axText.doc.removeDocumentListener(axText);
>     axText = null;
> }
> 
> 
> So we are trying to uninstall the JEditorPaneAccessibleHypertextSupport when 
> possible, but this PR isn't trying to account for other listeners.
> 
> Does this speak to your question, or is there a specific set of steps you'd 
> like to me to express as a unit test?

But it seems you don't need to use all that listeners? all that methods are in 
the JDK, can we just reset that references directly in "setters" w/o using 
listeners or properties/etc?

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/30401#discussion_r3151594022

Reply via email to