How to get the TableRow index (JavaFx TableView)

混江龙づ霸主 提交于 2019-12-25 01:26:29

问题


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.

The Question is:

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


回答1:


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



来源:https://stackoverflow.com/questions/23824061/how-to-get-the-tablerow-index-javafx-tableview

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