英文:
how to put css styling for one specific checkbox in checkboxGroup of vaadin 8
问题
以下是您要翻译的内容:
我有一个包含多个复选框的复选框组。我有一些复选框需要看起来不同,可以通过加粗文本或着色文本来实现,而这些样式不会因选择/取消选择而改变。
我有以下代码来构建复选框组。但是我无法为一个特定的复选框添加样式,因为我无法访问它。我该如何做呢?
CheckBoxGroup<ReferenceScreenResultAnswer> answersOptionGroup = new CheckBoxGroup<>(question.getText());
List<ReferenceScreenResultAnswer> checkBoxItems = new ArrayList<>();
answersOptionGroup.setItems(checkBoxItems);
.......
// 这是我想要为特定复选框/值添加样式的地方
for (Answer answer : preSelectedAnswer)
{
ReferenceScreenResultAnswer rsra = new ReferenceScreenResultAnswer();
rsra.setAnswer(answer);
rsra.setReferenceScreenResultQuestion(rsrq);
answersOptionGroup.select(rsra);
}
我可以单独处理复选框,如下所示
CheckBox cb = new CheckBox();
cb.setCaptionAsHtml(true);
cb.setCaption("<b> 你好 </b> 在那里");
但是我无法从CheckBoxGroup中访问单独的复选框。您有任何关于如何访问它们的想法吗?
英文:
I have a checkboxgroup which has multiple checkboxes. I have certain checkboxes which needs to look different, either by bold text or colored text ,which wont change irrespective of selection/unselection.
I have following code to build checkboxgroup. But I am not able to put style specific to one checkbox, because I dont have access to it. How can I do that
CheckBoxGroup<ReferenceScreenResultAnswer> answersOptionGroup = new CheckBoxGroup<>(question.getText());
List<ReferenceScreenResultAnswer> checkBoxItems = new ArrayList<>();
answersOptionGroup.setItems(checkBoxItems);
.......
// this is where i want to put CSS to specific checkbox/values
for (Answer answer : preSelectedAnswer)
{
ReferenceScreenResultAnswer rsra = new ReferenceScreenResultAnswer();
rsra.setAnswer(answer);
rsra.setReferenceScreenResultQuestion(rsrq);
answersOptionGroup.select(rsra);
}
I can do invidiual checkboxes like
CheckBox cb = new CheckBox();
cb.setCaptionAsHtml(true);
cb.setCaption("<b> hello </b> there");
But I am not able to access individual checkboxes from CheckBoxGroup. Any idea how to access them
答案1
得分: 1
我找到了答案:
// 为预选答案添加CSS样式,以使它们在选择方面看起来不同
answersOptionGroup.setItemCaptionGenerator(new ItemCaptionGenerator<ReferenceScreenResultAnswer>() {
@Override
public String apply(ReferenceScreenResultAnswer item) {
if (preSelectedAnswer.contains(item.getAnswer()))
return "<strong>" + item.getAnswer().toString() + "</strong>";
else
return item.getAnswer().toString();
}
});
英文:
i found the answer:
// css style the pre selected answer, so they look different irrespective
// of their selection
answersOptionGroup.setItemCaptionGenerator(new ItemCaptionGenerator<ReferenceScreenResultAnswer>()
{
@Override
public String apply(ReferenceScreenResultAnswer item)
{
if (preSelectedAnswer.contains(item.getAnswer()))
return "<strong>" + item.getAnswer().toString() + "</strong>";
else
return item.getAnswer().toString();
}
});
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论