I want to display HashMap contents in a JavaFX Tableview. Please find below the code I used to set the HashMap contents into the table columns. The problem I'm having is that it's displaying only one row. The for loop is iterating only 5 times: each time it is picking up the first value of the HashMap.
If I ignore the return SimpleObjectProperty line, the for loop is iterating over all the content in the HashMap.
final ObservableList<Map> data = FXCollections.observableArrayList();
data.addAll(HASHMAP);
TableColumn<Map.Entry, String> nCol = new TableColumn<Map.Entry, String>("Name");
nCol.setEditable(true);
nCol.setCellValueFactory(new Callback<TableColumn.CellDataFeatures<Entry, String>, ObservableValue<String>>() {
@Override
public ObservableValue<String> call(TableColumn.CellDataFeatures<Entry, String> p) {
Set <String> set=HASHMAP.keySet();
for (String key:HASHMAP.keySet())
{
String key1= key.toString();
return new SimpleObjectProperty<>(key.toString());
}
return null;
}
});
Table.setItems(data);
Table.getColumns().setAll(nCol,.........);