如何获取TableRow索引(JavaFx TableView) [英] How to get the TableRow index (JavaFx TableView)

查看:571
本文介绍了如何获取TableRow索引(JavaFx TableView)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个TableView,其中有一个客户端电子邮件列。在电子邮件列中有一个名为电子邮件的标签,应该根据标签所在的列来填充来自数据库的电子邮件。

I have a TableView in which I have a clients emails column. In the emails column there is a Label called emails that should get populated with emails from the database depending on the column in which the Label is on.

从中检索文本因此,为了获得特定的电子邮件地址,我需要获取行索引,并使用以下内容查询该特定电子邮件:

The text is retrieved from a database and therefore, to get a specific email address, I need to get the row index, and query for that particular email with something like:

"SELECT email from Clients WHERE clientID = " + rowItemRecord.getClientID());

到目前为止,我的方法如下:

My approach so far is as follows:

int itemRowIndex = getTableRow().getIndex();
NewClientPOJO rowItemRecord = (NewClientPOJO) table.getItems().get(itemRowIndex);

// Then
"SELECT email from Clients WHERE clientID = " + rowItemRecord.getClientID());

这不起作用。我得到一个空指针。

This doesn't work. I get a null pointer.

问题是:

如何获取TableView TableRow索引.. ..一个更好的方法将起作用。

How can I get the TableView TableRow index.... A better approach that will work.

推荐答案

我假设您必须先开始索引:
首先尝试if ... hasNext()然后index = ...
hasNext检查是否存在值,然后以此值启动索引。
我不确定方法hasnext的确切名称,我让你自己找到:)
Niko

I assume you must first start your index: Try first wiht "if ... hasNext()" then index=... hasNext check if a value exists, and then start the index at this value. I'm not sure of the exact name of the method "hasnext", I let you find this by yourself :) Niko

这篇关于如何获取TableRow索引(JavaFx TableView)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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