samedi 18 mai 2019

In JavaFX, how do you line up the labels with the CheckBoxes in a VBox layout?

I have created a TableView in JavaFX which dynamically loads VBoxs containing a list of CheckBoxs into in row. This is shown in the figure below:

enter image description here

As you can see in the figure, the labels next to the checkboxes do not line up with the checkbox its self.

I use the following to dynamically create the VBoxes:

private VBox getVBox(Map<Integer, String> item, Set<Integer> completed, String id) {
    VBox box = new VBox();
    box.setSpacing(0);
    box.setPadding(new Insets(3,3,3,3));

    for(Integer i : item.keySet()) {
        CheckBox checkbox = new CheckBox(item.get(i));
        checkbox.setId("item"+id+"-" + i.intValue());
        if(completed.contains(i)) {
            checkbox.setSelected(true);
        }
        checkbox.setPrefHeight(21);
        box.getChildren().add(checkbox);
    }

    return box;
}

Even if I remove the setSpacing setting and setPadding setting and setPrefHeight setting, the issue remains unchanged.

The only CSS which I have applied to this table which is not by default is as follows:

.table-view{
    -fx-background-color: transparent;
}

.table-view:focused{
    -fx-background-color: transparent;
}

.table-row-cell:odd{
    -fx-background-color: #E0E0E0;
    -fx-background-insets: 0, 0 0 1 0;
    -fx-padding: 0.0em;
}

.table-row-cell:even{
    -fx-background-color: #BBD9E0;
    -fx-background-insets: 0, 0 0 1 0;
    -fx-padding: 0.0em;
}

My Question: How can I make the checkbox labels line up with the checkboxes in a vertical manner? Can this not be done with a VBox?

Thank you for the assistance.




Aucun commentaire:

Enregistrer un commentaire