Hi I am trying to set focus on an item in a listview. After a user opens a file the item is added to the listview, but the issue I am having is that the listview is not sett
Assuming that the newly added item has an index of N
,
Selecting it:
listView.getSelectionModel().select(N);
Focusing on it:
listView.getFocusModel().focus(N);
Scrolling to it:
listView.scrollTo(N);
You can use combinations of these and preferably in Platform.runLater()
.
Scroll then select:
Platform.runLater(new Runnable() {
@Override
public void run() {
listView.scrollTo(N);
listView.getSelectionModel().select(N);
}
});