On Wed, 6 Aug 2025 15:49:19 GMT, Phil Race <p...@openjdk.org> wrote:

> > > Isn't this just a bug ? I get zero from the test whenever "-1" is the 
> > > direction - meaning scroll up - even if I use something like
> > > https://docs.oracle.com/en/java/javase/21/docs/api/java.desktop/javax/swing/JList.html#getScrollableUnitIncrement(java.awt.Rectangle,int,int)
> > 
> > 
> > If the `visibleRect` Rectangle points to the 1st row or row 0 and we are 
> > scrolling up i.e -1 direction there is no more space to scroll up so 
> > `getScrollableUnitIncrement` returns 0. If we modify the testcase to have 
> > `Rectangle cell = list.getCellBounds(data.length-1, data.length-1);` 
> > instead of `list.getCellBounds(0, 0);` to point to last cell, it returns 
> > positive number for -1 direction too
> 
> As I wrote it returns zero for me no matter what. Eg if I use Rectangle cell 
> = list.getCellBounds(1, 2);
> 
> so why is that ?

That is because of test does wrap layout via this line 
`list.setLayoutOrientation(JList.HORIZONTAL_WRAP);`
whereby 1st and 2nd cell are in the same row 0 and then it wraps to next line 
where it displays 3rd and 4th cell so if we call 
`list.getCellBounds(1, 2)` it will still result in pointing to 1st row or row 0
 
but if we call getCellBounds(2, 3) it will have positive number and not 0 as 
then it will select the 2nd row because cell 3 is in 2nd row.

If we remove `list.setLayoutOrientation(JList.HORIZONTAL_WRAP);` then it will 
layout each cell in separate line so we will get positive number for 
`list.getCellBounds(1, 2)`  too as then it will select the 2nd row and not 1st 
row for which scrolling is not required.

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

PR Comment: https://git.openjdk.org/jdk/pull/26500#issuecomment-3162394026

Reply via email to