Skip to content

Commit 3b45c92

Browse files
authored
Fix first cell not showing sometimes (#110)
1 parent ea01ea6 commit 3b45c92

2 files changed

Lines changed: 35 additions & 0 deletions

File tree

src/main/java/org/fxmisc/flowless/Navigator.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@ private void cropToNeighborhoodOf( int itemIndex ) {
146146
int begin = Math.max( 0, getFirstVisibleIndex() );
147147
int end = Math.max( itemIndex, getLastVisibleIndex() );
148148
positioner.cropTo( Math.min( begin, itemIndex ), end+1 );
149+
// Needed for correct layout in some situations
150+
sizeTracker.getAverageLengthEstimate();
149151
}
150152

151153
@Override
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package org.fxmisc.flowless;
2+
3+
import javafx.collections.FXCollections;
4+
import javafx.collections.ObservableList;
5+
import javafx.scene.control.Label;
6+
import javafx.scene.Scene;
7+
import javafx.stage.Stage;
8+
import org.junit.Test;
9+
10+
import static org.junit.Assert.assertEquals;
11+
12+
public class FirstCellCreationAndLayoutTest extends FlowlessTestBase
13+
{
14+
private VirtualFlow<Label, ?> flow;
15+
16+
@Override
17+
public void start(Stage stage)
18+
{
19+
Label first = new Label( "First Item" );
20+
Label second = new Label( "Second Item" );
21+
ObservableList<Label> items = FXCollections.observableArrayList( first, second );
22+
flow = VirtualFlow.createVertical( items, Cell::wrapNode );
23+
24+
stage.setScene( new Scene( flow, 200, 100 ) );
25+
stage.show();
26+
}
27+
28+
@Test
29+
public void does_the_first_cell_layout_correctly()
30+
{
31+
assertEquals( 0, flow.getFirstVisibleIndex() );
32+
}
33+
}

0 commit comments

Comments
 (0)