On Tue, 28 Apr 2026 04:36:13 GMT, Sergey Bylokhov <[email protected]> wrote:

>>> 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?

Can you clarify which setter and which reference you're referring to?

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

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

Reply via email to