JavaFX TableView如何获取单元格的数据? [英] JavaFX TableView how to get cell's data?
本文介绍了JavaFX TableView如何获取单元格的数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用该方法来获取整个对象。
I'm using that method to get whole object.
tableView.getSelectionModel().getSelectedItem()
如何从单个单元格获取数据?
我的意思是喜欢 S20BJ9DZ300266 as String?
How can I get data from single cell?
I mean like get S20BJ9DZ300266 as String?
推荐答案
假设您知道某些内容被选中,您可以
Assuming you know something is selected, you can do
TablePosition pos = table.getSelectionModel().getSelectedCells().get(0);
int row = pos.getRow();
// Item here is the table view type:
Item item = table.getItems().get(row);
TableColumn col = pos.getTableColumn();
// this gives the value in the selected cell:
String data = (String) col.getCellObservableValue(item).getValue();
这篇关于JavaFX TableView如何获取单元格的数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文