TableCell, getting its position in TableView

前端 未结 1 900
半阙折子戏
半阙折子戏 2021-01-22 09:25

How can I get position of TableCell in class implementation so I can do something like this: ?

@Override
public void updateItem(Integer item, boolean empty) {
           


        
相关标签:
1条回答
  • 2021-01-22 10:14

    You can get the actual TableColumn with this.getTableColumn();. If you really need the index, you could do

    TableColumn<...> column = getTableColumn();
    int colIndex = getTableView().getColumns().indexOf(column);
    

    which is a bit ugly (and slow). However, just knowing the column should be enough. (Additionally, you really "know this already"; your table cell comes from a table cell factory, which is attached to a column; so you can always figure the column index and pass it to the cell when you create it.)

    The row index is just

    this.getIndex();
    

    See the Javadocs for all available methods.

    0 讨论(0)
提交回复
热议问题