diff --git a/src/main/java/org/fxmisc/flowless/Navigator.java b/src/main/java/org/fxmisc/flowless/Navigator.java index fa2dcdc..ec34aaf 100644 --- a/src/main/java/org/fxmisc/flowless/Navigator.java +++ b/src/main/java/org/fxmisc/flowless/Navigator.java @@ -146,6 +146,8 @@ private void cropToNeighborhoodOf( int itemIndex ) { int begin = Math.max( 0, getFirstVisibleIndex() ); int end = Math.max( itemIndex, getLastVisibleIndex() ); positioner.cropTo( Math.min( begin, itemIndex ), end+1 ); + // Needed for correct layout in some situations + sizeTracker.getAverageLengthEstimate(); } @Override diff --git a/src/test/java/org/fxmisc/flowless/FirstCellCreationAndLayoutTest.java b/src/test/java/org/fxmisc/flowless/FirstCellCreationAndLayoutTest.java new file mode 100644 index 0000000..8ec60b0 --- /dev/null +++ b/src/test/java/org/fxmisc/flowless/FirstCellCreationAndLayoutTest.java @@ -0,0 +1,33 @@ +package org.fxmisc.flowless; + +import javafx.collections.FXCollections; +import javafx.collections.ObservableList; +import javafx.scene.control.Label; +import javafx.scene.Scene; +import javafx.stage.Stage; +import org.junit.Test; + +import static org.junit.Assert.assertEquals; + +public class FirstCellCreationAndLayoutTest extends FlowlessTestBase +{ + private VirtualFlow flow; + + @Override + public void start(Stage stage) + { + Label first = new Label( "First Item" ); + Label second = new Label( "Second Item" ); + ObservableList