jeudi 23 mai 2019

How can I add a CheckBox to the GridPane after the scene has already been loaded/shown?

I'm writing a program that sorts a list of Json objects and then formats/prints the data in each Json Object. I've created a GUI that allows the user to select which JSON Strings from the Json Object they would like to include in the final print.

To do this, I have a button for the user to press that loads a HashMap of String/Checkbox Pairs, where the string is the KEY_NAME of the respective JSON String. What I want to do is, after the scene has been loaded and the GUI shown, add the CheckBox's from the map to an existing GridPane in the scene.

I've tried the version below, and also tried it without re-adding the gpane to the AnchorPane. So far nothing has caused the scene to refresh. How can I accomplish this?

public void addCheckboxes(GridPane gpane, AnchorPane pane, Map<String, CheckBox> map){
    Iterator it = map.entrySet().iterator();
    int row = 1, col = 0;
    while(it.hasNext()){
        Map.Entry pair = (Map.Entry) it.next();
        gpane.add((CheckBox) pair.getValue(), col, row);

        pane.getChildren().add(gpane);

        row++;
    }
}




Aucun commentaire:

Enregistrer un commentaire