[英]In JavaFX, how do you line up the labels with the CheckBoxes in a VBox layout?
我已經在JavaFX中創建了一個TableView
,它動態地將包含CheckBox
列表的VBox
加載到行中。 如下圖所示:
如您在圖中所看到的,復選框旁邊的標簽與復選框本身不對齊。
我使用以下內容動態創建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;
}
即使我刪除了setSpacing
設置和setPadding
設置以及setPrefHeight
設置,問題仍然保持不變。
我應用於此表的唯一CSS並非默認情況如下:
.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;
}
我的問題:如何使復選框標簽與復選框垂直對齊? VBox
不能做到這一點嗎?
感謝您的幫助。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.