RFR: 4265389: JSplitPane does not support ComponentOrientation [v6]

Prasanta Sadhukhan psadhukhan at openjdk.org
Mon Jul 22 07:18:32 UTC 2024


On Mon, 22 Jul 2024 07:08:47 GMT, Prasanta Sadhukhan <psadhukhan at openjdk.org> wrote:

>> src/java.desktop/share/classes/javax/swing/JSplitPane.java line 375:
>> 
>>> 373:         Component leftComponent = this.getLeftComponent();
>>> 374:         Component rightComponent = this.getRightComponent();
>>> 375:         if (this.getComponentOrientation().equals(ComponentOrientation.RIGHT_TO_LEFT)) {
>> 
>> Is it a good idea to use `isLeftToRight()` method to determine the component orientation? 
>> As per [ComponentOrientation spec](https://docs.oracle.com/en%2Fjava%2Fjavase%2F22%2Fdocs%2Fapi%2F%2F/java.desktop/java/awt/ComponentOrientation.html) 
>> 
>>  >Components whose view and controller code depends on orientation should use the isLeftToRight() and isHorizontal() methods to determine their behavior. They should not include switch-like code that keys off of the constants, such as:
>> if (orientation == LEFT_TO_RIGHT) {
>>    ...
>>  } else if (orientation == RIGHT_TO_LEFT) {
>>    ...
>>  } else {
>>    // Oops
>>  }
>> This is unsafe, since more constants may be added in the future and since it is not guaranteed that orientation objects will be unique.`
>
> good observation..will modify...

There's a problem to it as ComponentOrientation can be LTR, RTL or UNKNOWN (ie orientation not set) so just checking for isLeftToRIght will not work as !LTR can be RTL or UNKNOWN so it will not work for the present scenario so I guess we need to use the present way only..

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

PR Review Comment: https://git.openjdk.org/jdk/pull/20214#discussion_r1686077028


More information about the client-libs-dev mailing list