Skip to content

Commit eaddb0f

Browse files
author
Johan Vos
committed
8291908: VirtualFlow creates unneeded empty cells
Reviewed-by: kcr, aghaisas
1 parent 33534cb commit eaddb0f

File tree

3 files changed

+40
-2
lines changed

3 files changed

+40
-2
lines changed

Diff for: modules/javafx.controls/src/main/java/javafx/scene/control/skin/VirtualFlow.java

+5-1
Original file line numberDiff line numberDiff line change
@@ -2072,7 +2072,7 @@ protected T getFirstVisibleCellWithinViewport() {
20722072
*/
20732073
void addLeadingCells(int currentIndex, double startOffset) {
20742074
// The offset will keep track of the distance from the top of the
2075-
// viewport to the top of the current index. We will increment it
2075+
// viewport to the top of the current index. We will decrement it
20762076
// as we lay out leading cells.
20772077
double offset = startOffset;
20782078
// The index is the absolute index of the cell being laid out
@@ -2877,6 +2877,10 @@ private double computeViewportOffset(double position) {
28772877
double p = com.sun.javafx.util.Utils.clamp(0, position, 1);
28782878
double bound = 0d;
28792879
double estSize = estimatedSize / getCellCount();
2880+
double maxOff = estimatedSize - getViewportLength();
2881+
if ((maxOff > 0) && (absoluteOffset > maxOff)) {
2882+
return maxOff - absoluteOffset;
2883+
}
28802884

28812885
for (int i = 0; i < getCellCount(); i++) {
28822886
double h = getCellSize(i);

Diff for: modules/javafx.controls/src/test/java/test/javafx/scene/control/TreeTableViewTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -3669,7 +3669,7 @@ protected <T> void assert_rt35857(ObservableList<T> items, MultipleSelectionMode
36693669
// However, for now, we'll test on the assumption that across all
36703670
// platforms we only get one extra cell created, and we can loosen this
36713671
// up if necessary.
3672-
assertEquals(cellCountAtStart + 14, rt36452_instanceCount);
3672+
assertTrue(rt36452_instanceCount < cellCountAtStart + 15);
36733673

36743674
sl.dispose();
36753675
}

Diff for: modules/javafx.controls/src/test/java/test/javafx/scene/control/skin/VirtualFlowTest.java

+34
Original file line numberDiff line numberDiff line change
@@ -1254,6 +1254,40 @@ public void testSheetChildrenRemainsConstant() {
12541254
assertEquals("Wrong number of sheet children after removing all items", 12, sheetChildrenSize);
12551255
}
12561256

1257+
@Test
1258+
// See JDK-8291908
1259+
public void test_noEmptyTrailingCells() {
1260+
flow = new VirtualFlowShim();
1261+
flow.setVertical(true);
1262+
flow.setCellFactory(p -> new CellStub(flow) {
1263+
@Override
1264+
protected double computeMaxHeight(double width) {
1265+
return computePrefHeight(width);
1266+
}
1267+
1268+
@Override
1269+
protected double computePrefHeight(double width) {
1270+
return (getIndex() > 100) ? 1 : 20;
1271+
}
1272+
1273+
@Override
1274+
protected double computeMinHeight(double width) {
1275+
return computePrefHeight(width);
1276+
}
1277+
1278+
});
1279+
flow.setCellCount(100);
1280+
flow.setViewportLength(1000);
1281+
flow.resize(100, 1000);
1282+
pulse();
1283+
flow.sheetChildren.addListener((InvalidationListener) (o) -> {
1284+
int count = ((List) o).size();
1285+
assertTrue(Integer.toString(count), count < 101);
1286+
});
1287+
flow.scrollTo(99);
1288+
pulse();
1289+
}
1290+
12571291
private ArrayLinkedListShim<GraphicalCellStub> circlelist = new ArrayLinkedListShim<GraphicalCellStub>();
12581292

12591293
private VirtualFlowShim createCircleFlow() {

0 commit comments

Comments
 (0)