On Tue, 26 Aug 2025 07:11:53 GMT, Prasanta Sadhukhan <[email protected]> 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 one > additional commit since the last revision: > > Fire property change notification instead I dont think its a workaround...The `layoutManager` can be either horizontal or vertical and we are updating the components based on the current layouting..It's only we are using the currently existing property but the contents is exactly what we want it be done even if it were to be a new property.. I dont see any problem with our existing tests additionally Other suggestion i.e using new property or public method will need a CSR to our java spec which will prevent it from backporting this fix to previous JDK versions ------------- PR Comment: https://git.openjdk.org/jdk/pull/26893#issuecomment-3235581063
