On Fri, 5 Sep 2025 08:16:40 GMT, Prasanta Sadhukhan <[email protected]>
wrote:
> And if the rectangle you pass in has a y that is = the height of the list,
> then scrolling in a positive direction also returns 0.
> If it is GREATER than the height, then I get back a negative increment !
I tried
Rectangle cell = list.getCellBounds(1, data.length);
cell.y = list.getHeight() + 10;
int unit = list.getScrollableUnitIncrement(
cell,
SwingConstants.VERTICAL,
-1);
System.out.println("Scrollable unit increment: " + unit);
and I get 117 in upward (-1) direction and -99 in downward (1) direction..
so it seems `getScrollableUnitIncrement` finds from `locationToIndex` that it's
last row so `r.y` points to TOP of last cell (90) but `visibleRect.y` points to
height past the last cell(207) so it has to backtrack -99 pixels [last cell
height=18 - (207-90) = 18-117] logically but I guess we need to restrict it to
0 since there is no incremental scrolling that can be done
> > And if the rectangle you pass in has a y that is = the height of the list,
> > then scrolling in a positive direction also returns 0.
> > If it is GREATER than the height, then I get back a negative increment !
>
> I tried
>
> ```
> Rectangle cell = list.getCellBounds(1, data.length);
> cell.y = list.getHeight() + 10;
> int unit = list.getScrollableUnitIncrement(
> cell,
> SwingConstants.VERTICAL,
> -1);
> System.out.println("Scrollable unit increment: " + unit);
> ```
>
> and I get 117 in upward (-1) direction and -99 in downward (1) direction.. so
> it seems `getScrollableUnitIncrement` finds from `locationToIndex` that it's
> last row so `r.y` points to TOP of last cell (90) but `visibleRect.y` points
> to height past the last cell(207) so it has to backtrack -99 pixels [last
> cell height=18 - (207-90) = 18-117] logically but I guess we need to restrict
> it to 0 since there is no incremental scrolling that can be done
Test added
-------------
PR Comment: https://git.openjdk.org/jdk/pull/26500#issuecomment-3370104712