C
C
chelovek_rediska2016-12-03 23:38:32
JavaFX
chelovek_rediska, 2016-12-03 23:38:32

How to add data from collection to TableView?

There is one column to which ordinary string elements must be passed through the collection.

@FXML
TableView TableView;

@FXML
TableColumn Result;


@FXML
private void StartSearch(ActionEvent event)  {

        ObservableList<SimpleStringProperty> data = FXCollections.observableArrayList();
        data.add(new SimpleStringProperty("Florida"));
        data.add(new SimpleStringProperty("NY"));
        data.add(new SimpleStringProperty("NJ"));

        TableView.setItems(data);

        Result.setCellValueFactory(new PropertyValueFactory("result"));

        TableView.getColumns().setAll(Result);

    }

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question