JavaFX使用表索引获取单元数据的最简单方法

时间:2016-12-12 16:04:35

标签: javafx tableview

有没有最简单的方法在不使用cellfactory函数的情况下使用表索引值在javafx中获取tableview的单元格数据。我看起来像这样简单的单行代码

  getValueAt(1,2);//1=column number 2=row number

所以我可以访问column = 1和row = 2的单元格数据。提前谢谢

2 个答案:

答案 0 :(得分:5)

您可以使用TableColumn获取可观察量并使用getValue

public static Object getValueAt(TableView table, int column, int row) {
    return table.getColumns().get(column).getCellObservableValue(row).getValue();
}

答案 1 :(得分:0)

您还可以使用以下代码。当您使用鼠标选择行

ProcessDetail pd =
 (ProcessDetail)tableDefined.getSelectionModel().getSelectedItem();
System.out.println("Value is in this row which is selected"+pd.getStatus());