当播放器最后滚动时,我需要在列表中添加新项目。因此,如何检测到Scrollpane
到达末尾或最大Y
?
private Table list;
private ScrollPane scrollPane;
private void buildPlayersList() {
list = new Table();
scrollPane = new ScrollPane(list);
}
private boolean isTheEnd() {
// condition !!!
return scrollPane.getScrollY() >= scrollPane.getMaxY();
}
@Override
public void onTheEndRequest() {
int offset = list.getRows();
int limit = 10;
Actor player = this.getPlayer(offset, limit);
list.add(player).row();
}
private Actor getPlayer(int offset, int limit) {
// retrieve player from database
// ......
Player player = database.getPlayer();
Label label = new Label(player.getName(), style);
return label;
}
答案 0 :(得分:2)
如本other question中所述,您可以使用ChangeListener寻找对getScrollY的更改以执行ScrollY和MaxY的比较。
s1.vvalueProperty().addListener(new ChangeListener<Number>() {
public void changed(ObservableValue<? extends Number> ov,
Number old_val, Number new_val) {
// if ScrollY == maxY; then displayMoreItems
System.out.println(new_val.intValue());
}
});