Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010, 2025, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2010, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -1138,13 +1138,6 @@ void adjustPosition() {
cell.requestLayout();
}
}

// Also request layout for cells in the pile. As soon as those are reused (and therefore added),
// they will do their layout.
for (T cell : pile) {
cell.requestLayout();
}

needsCellsLayout = false;
// yes, we return here - if needsCellsLayout was set to true, we
// only did it to do the above - not rerun the entire layout.
Expand Down Expand Up @@ -1428,6 +1421,7 @@ protected T getAvailableCell(int prefIndex) {
if (cell.getParent() == null) {
sheetChildren.add(cell);
}
cell.setVisible(true);

return cell;
}
Expand Down Expand Up @@ -2844,17 +2838,14 @@ private void addToPile(T cell) {
private void cleanPile() {
boolean wasFocusOwner = false;

// Set all cells in the pile to invisible
// We do NOT remove them from sheetChildren to avoid O(n*m) complexity
for (int i = 0, max = pile.size(); i < max; i++) {
T cell = pile.get(i);
wasFocusOwner = wasFocusOwner || doesCellContainFocus(cell);
cell.setVisible(false);
}

// Remove all cells that are in the pile and therefore not relevant anymore.
if (sheetChildren.size() != cells.size()) {
sheetChildren.removeAll(pile);
}

// Fix for JDK-8095710: Rather than have the cells do weird things with
// focus (in particular, have focus jump between cells), we return focus
// to the VirtualFlow itself.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2102,20 +2102,26 @@ public void testSheetChildrenAreAlwaysTheAmountOfVisibleCells() {
flow.resize(250, 240);
pulse();

assertEquals(10, flow.sheetChildren.size());
assertEquals(flow.cells, flow.sheetChildren);
// Count only visible cells in sheetChildren
long visibleCount = flow.sheetChildren.stream().filter(Node::isVisible).count();
assertEquals(10, visibleCount);
// Note: sheetChildren may contain invisible cells from the pile,
// but flow.cells should be a subset of sheetChildren
assertTrue(flow.sheetChildren.containsAll(flow.cells));

flow.resize(250, 480);
pulse();

assertEquals(20, flow.sheetChildren.size());
assertEquals(flow.cells, flow.sheetChildren);
visibleCount = flow.sheetChildren.stream().filter(Node::isVisible).count();
assertEquals(20, visibleCount);
assertTrue(flow.sheetChildren.containsAll(flow.cells));

flow.resize(250, 240);
pulse();

assertEquals(10, flow.sheetChildren.size());
assertEquals(flow.cells, flow.sheetChildren);
visibleCount = flow.sheetChildren.stream().filter(Node::isVisible).count();
assertEquals(10, visibleCount);
assertTrue(flow.sheetChildren.containsAll(flow.cells));
}

}
Expand Down