How can I populate a TableView in JavaFX by using Arraylist?
12,321
Solution 1
You must use a ObservableList
as your datasource and to achieve this when you have a List
you can use:
FXCollections.observableList(yourList);
Solution 2
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);
Author by
Rajesh Kumar Dash
Developer based out from Bangalore .Have expertise with java,Eclipse Rcp,Emf,Data Engineering,Rest ApI Have some experience with Javascript front end development
Updated on June 15, 2022Comments
-
Rajesh Kumar Dash almost 2 years
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