javafx listview auto scroll to the end

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



javafx listview auto scroll to the end



I'm using JavaFX ListView for the chatroom body of my Chat application. I add to the listview when a message comes or is being sent. This works well but I always have to scroll to find the latest message. Is there any way that I can auto scroll to the bottom so that the latest messages are displayed without having to scroll all the way down?





Have a look here and maybe there, too...
– deHaar
Aug 8 at 11:14





Hi thanks for the quick response. The thing is I'm not using a scroll pane. Im using only a ListView. Is there any workaround for this?
– Sachini Wickramaratne
Aug 8 at 11:21




1 Answer
1



Use ListView.scrollTo for this purpose:


ListView.scrollTo


public static <T> void addItem(ListView<T> listView, T item)
List<T> items = listView.getItems();
int index = items.size();
items.add(item);
listView.scrollTo(index);





Would you by any chance know how to access the cell at a given index?
– Sachini Wickramaratne
Aug 9 at 6:23





@SachiniWickramaratne Why do you want to do this? That is usually a bad idea (depending on what exactly "accessing the cell" means). Cells for certain indices may or may not be present at a given time and may come into view later. If this is about highlighting the new object(s) or something like this: This is possible but I cannot properly explain it in comments. I suggest asking a new question about this.
– fabian
Aug 9 at 11:01





this is the purpose stackoverflow.com/questions/51765043/…
– Sachini Wickramaratne
Aug 9 at 11:04







By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

How to determine optimal route across keyboard