How to select/highlight next row in TableView (JAVAFX)

青春壹個敷衍的年華 提交于 2019-12-25 03:15:14

问题


I'm making a media player in JavaFX. I'm displaying the songs in a TableView object. And whenever I press the Skip button, I would like it to highlight the next row, so that the user can see which song from the playlist, that he is listening to.

This is the code for the TableView.

I would like it to get the selected element, and then select/highlight the next element for me, whenever a certain method gets invoked.

    @FXML
private TableView<Song> defaultTableView;

// 1) Song Title

@FXML
private TableColumn<Song, String> songTitleColumn;

// 2) Song artist

@FXML
private TableColumn<Song, String>  songArtistColumn;

// 3) Song album
@FXML
private TableColumn<Song, String>  songAlbumColumn;

回答1:


Call selectNext on the selectionModel of the table:

defaultTableView.getSelectionModel().selectNext();

The selection model also allows you to replace the selection with the selection of a specific item index using clearAndSelect.



来源:https://stackoverflow.com/questions/54179474/how-to-select-highlight-next-row-in-tableview-javafx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!