RFR: 8365886: JSplitPane loses track of the left component when the component orientation is changed [v2]
Alan Snyder
javalists at cbfiddle.com
Mon Aug 25 14:16:19 UTC 2025
That is a heavy handed solution.
Isn’t this better:
layoutManager.updateComponents();
> On Aug 24, 2025, at 2:03 AM, Prasanta Sadhukhan <psadhukhan at openjdk.org> wrote:
>
>> When the component orientation is changed from LTR to RTL or the other way around, JSplitPane exchanges the left and right components. However, it does this by adding and removing components instead of swapping the leftComponent and rightComponent fields which results in leftComponent field is left as null.
>>
>> This is because when JSplitPane calls `setLeftComponent(rightComponent)` it calls `JSplitPane.addImpl` which calls `super.addImpl`
>> which [removes] https://github.com/openjdk/jdk/blob/f423e1d9ad37135abacb8deb2d2151e21768a23e/src/java.desktop/share/classes/java/awt/Container.java#L1118 the component from the JSplitPane as it calls `JSplitPane.remove` so the sequence is
>> At start `leftComponent = Red, rightComponent = Green`
>>
>> before `super.addImpl` is called in `JSplitPane.addImpl` the
>>
>> `leftComponent = Green, rightComponent = Green`
>>
>> After super.addImpl is called, it calls [JSplitPane.remove] (https://github.com/openjdk/jdk/blob/f423e1d9ad37135abacb8deb2d2151e21768a23e/src/java.desktop/share/classes/javax/swing/JSplitPane.java#L918) where it sets
>> leftComponent = null.
>>
>> so we have
>> leftComponent = null, rightComponent = Green and then it calls [super.remove] (https://github.com/openjdk/jdk/blob/f423e1d9ad37135abacb8deb2d2151e21768a23e/src/java.desktop/share/classes/javax/swing/JSplitPane.java#L922) which calls `JSplitPane.remove(index)` and since index=1 because "Green" is 1 it removes rightComponent
>> so we have now
>> leftComponent = null, rightComponent = null
>>
>> so when we now call [setRightComponent](https://github.com/openjdk/jdk/blob/f423e1d9ad37135abacb8deb2d2151e21768a23e/src/java.desktop/share/classes/javax/swing/JSplitPane.java#L382) it sets rightComponent to Red but leftComponent is not set and is still null.
>>
>> So fix is to just swap the left and right component in setComponentOrientation call itself without using Container add/remove components
>
> Prasanta Sadhukhan has updated the pull request incrementally with two additional commits since the last revision:
>
> - update bugid
> - Update component nodes
>
> -------------
>
> Changes:
> - all: https://git.openjdk.org/jdk/pull/26893/files
> - new: https://git.openjdk.org/jdk/pull/26893/files/018d019f..6931e97d
>
> Webrevs:
> - full: https://webrevs.openjdk.org/?repo=jdk&pr=26893&range=01
> - incr: https://webrevs.openjdk.org/?repo=jdk&pr=26893&range=00-01
>
> Stats: 3 lines in 2 files changed: 1 ins; 0 del; 2 mod
> Patch: https://git.openjdk.org/jdk/pull/26893.diff
> Fetch: git fetch https://git.openjdk.org/jdk.git pull/26893/head:pull/26893
>
> PR: https://git.openjdk.org/jdk/pull/26893
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/client-libs-dev/attachments/20250825/a81af6d9/attachment-0001.htm>
More information about the client-libs-dev
mailing list