2

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      
4
  • Do you have some code that you actually have tried and not succeeded? Commented Aug 23, 2013 at 12:25
  • I have tried with hashmap but i couldnot do it.And i am a swt programmer all these javafx stuff is alien to me Commented Aug 23, 2013 at 12:50
  • did you put it inside a ObservableList? Commented Aug 23, 2013 at 12:57
  • OP asked how to populate a TableView, why are the answers talking about ListView? Commented Jul 22, 2017 at 20:04

2 Answers 2

2

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

FXCollections.observableList(yourList);
Sign up to request clarification or add additional context in comments.

1 Comment

but what about cell factory...plz check my new edited question
1

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

2 Comments

i donot want to use listview as i have multiple columns .. But i donot want to use any model as no of columns depending on the items on the list i have edited the question please check.
@Rajesh. Just use dummy model and get rid of all low level API complexities. Or use multiple listviews.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.