如何在TableView(JAVAFX)中选择/突出显示下一行 [英] How to select/highlight next row in TableView (JAVAFX)

查看:71
本文介绍了如何在TableView(JAVAFX)中选择/突出显示下一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用JavaFX制作媒体播放器.我在TableView对象中显示歌曲.每当我按下跳过"按钮时,我都希望它突出显示下一行,以便用户可以看到播放列表中正在收听的歌曲.

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.

这是TableView的代码.

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;

推荐答案

在表的 selectionModel 上调用 selectNext :

defaultTableView.getSelectionModel().selectNext();

选择模型还允许您使用 clearAndSelect 用特定项目索引的选择替换选择.

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

这篇关于如何在TableView(JAVAFX)中选择/突出显示下一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆