我已经在JavaFX中创建了一个TableView
,该行将包含VBox
列表的CheckBox
动态加载到行中。如下图所示:
从图中可以看出,复选框旁边的标签与复选框本身不对齐。
我使用以下内容动态创建VBox:
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
不能做到这一点吗?
谢谢您的帮助。
答案 0 :(得分:0)
我建议您使用ScenicView tool并检查应设置哪个元素以获取垂直对齐方式
下载它作为库添加并在以下行中放入代码:
ScenicView.show(current scene instance);