Skip to content

Commit

Permalink
Fix first cell not showing sometimes (#110)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jugen committed Aug 23, 2022
1 parent ea01ea6 commit 3b45c92
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/main/java/org/fxmisc/flowless/Navigator.java
Expand Up @@ -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
Expand Down
@@ -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<Label, ?> flow;

@Override
public void start(Stage stage)
{
Label first = new Label( "First Item" );
Label second = new Label( "Second Item" );
ObservableList<Label> items = FXCollections.observableArrayList( first, second );
flow = VirtualFlow.createVertical( items, Cell::wrapNode );

stage.setScene( new Scene( flow, 200, 100 ) );
stage.show();
}

@Test
public void does_the_first_cell_layout_correctly()
{
assertEquals( 0, flow.getFirstVisibleIndex() );
}
}

0 comments on commit 3b45c92

Please sign in to comment.