I basically am trying to populate a table with a class that contains a string field and a map with arraylist as value.
EDIT: So what I want in the table is is something like this:
Student name | Science |
---|---|
Bro Man | Passs |
--- | Excellent |
The class
public class ItemList {
private String studentNameList;
private HashMap<String, ArrayList<SimpleStringProperty>> remarksList;
public String getStudentNameList() {
return studentNameList;
}
public void setStudentNameList(String studentNameList) {
this.studentNameList = studentNameList;
}
public HashMap<String, ArrayList<SimpleStringProperty>> getRemarksList() {
return remarksList;
}
public void setRemarksList(HashMap<String, ArrayList<SimpleStringProperty>> remarksList) {
this.remarksList = remarksList;
}
}
The controller class has a tableview that will hold the class entries I have a loadTable method that loads the class into the tableview
The controller class
public class HelloController implements Initializable {
@FXML
private TableView tvTable;
// Observable object to hold the classes
private ObservableList<Item> tablelist = FXCollections.observableArrayList();
@Override
public void initialize(URL url, ResourceBundle resourceBundle) {
// Item with arraylist as value
ItemList itemlist = new ItemList();
itemlist.setStudentNameList("Bro Man");
HashMap <String, ArrayList<SimpleStringProperty>> remarks = new HashMap<>();
ArrayList<SimpleStringProperty> remarksString = new ArrayList<>();
remarksString.add(new SimpleStringProperty("Pass"));
remarksString.add(new SimpleStringProperty("Excellent"));
remarks.put("Science",remarksString);
itemlist.setRemarksList(remarks);
tablelist.add(itemlist);
Method to load table call
loadTableList(tablelist);
}
The method
private void loadTableList(ObservableList<ItemList> remarks) {
tvTable.setItems(remarks);
tvTable.setVisible(true);
TableColumn<ItemList, String> column = new TableColumn<ItemList, String>("student name");
column.setCellValueFactory(cd -> new SimpleStringProperty(cd.getValue().getStudentNameList()));
tvTable.getColumns().add(column);
// The looping through the hashmap containing arraylist value
for (Map.Entry<String, ArrayList<SimpleStringProperty>> entry : remarks.get(0).getRemarksList().entrySet()) {
// Using the key of the map as column name
TableColumn<ItemList, Number> col = new TableColumn<ItemList, Number>(entry.getKey());
// What should the code here contains to loop through the arraylist of the values and use as the rows
}
}
How do I loop through the hashmap arraylist
Maybe the beginning of the loop itself NOT right I might need a better solution