Tomáš Čičman
Tomáš Čičman

Reputation: 75

JavaFX How to get all values of one column from TableView?

I would like to get all data of one column from my TableView after Button click.

I found this code

    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();

But this is code for selected cell and i have button and all cells of one column.

Can you help me pls? Thankyou.

Upvotes: 3

Views: 17304

Answers (1)

James_D
James_D

Reputation: 209225

Just do the same thing for all elements of table.getItems():

TableColumn<MyDataType, String> column = ... ; // column you want

List<String> columnData = new ArrayList<>();
for (MyDataType item : table.getItems()) {
    columnData.add(col.getCellObservableValue(item).getValue());
}

where MyDataType is the data type of the TableView.

Upvotes: 8

Related Questions