[英]How to get row referenced object from within TableCell in JavaFX?
I would like to have custom TableCell<S,T>
class, which behaves depending on row object. 我想拥有自定义TableCell<S,T>
类,该类的行为取决于行对象。 By "row object" I mean object of type S
, not T
. “行对象”是指类型S
而不是T
对象。
Apparently, Cell#getItem()
is not what I need, since it return T
. 显然, Cell#getItem()
不是我所需要的,因为它返回T
cell.getTableView().getItems().get(cell.getIndex())
or 要么
(S) cell.getTableRow().getItem()
The second one needs a cast because, for some inexplicable reason, getTableRow()
returns a raw TableRow
, not a TableRow<S>
. 第二个需要转换,因为出于某种无法解释的原因, getTableRow()
返回原始TableRow
,而不是TableRow<S>
。
You may need null checks in the chain of method calls, depending on where you are doing this. 您可能需要在方法调用链中进行空检查,具体取决于执行此操作的位置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.