Rajesh Kumar Dash
Rajesh Kumar Dash

Reputation: 2277

How can I populate a TableView in JavaFX by using Arraylist?

I want to populate table view in javafx by using array list .I do not want to use any model .i want to make array list as my source of data for populating tableview .

Code:


List<Double> doubles = new ArrayList<Double>();
    doubles.add(12.12d);
    ObservableList<Double> names = FXCollections.observableArrayList(doubles);

    TableView table_view = new TableView<>(names);

    firstDataColumn.setCellFactory(?????);/// here the problem comes what is the cell factory in case of arraylist      

Upvotes: 2

Views: 12847

Answers (2)

Uluk Biy
Uluk Biy

Reputation: 49185

If there is no model then you want to show only one column list. So after taking assumption of that your arraylist's object type is the wrapper class (of the primitive data types) like Integer, Double, String etc., you can use ListView instead of TableView.

List<Double> doubles = new ArrayList<Double>();
doubles.add(12.12d);
ObservableList<Double> names = FXCollections.observableArrayList(doubles);
ListView<Double> listView = new ListView<Double>(names);

Upvotes: 1

Diego Urenia
Diego Urenia

Reputation: 1630

You must use a ObservableList as your datasource and to achieve this when you have a List you can use:

FXCollections.observableList(yourList);

Upvotes: 2

Related Questions