如何将一个特定复选框的css样式放在复选框中vaadinGroup 8

问题描述

我有一个复选框组,其中有多个复选框。我有一些需要通过粗体文本或彩色文本看起来不同的复选框,无论选择/取消选择,它们都不会改变。 我有以下代码来构建复选框组。但是我无法将样式特定于一个复选框,因为我无权访问它。我该怎么办

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);
}

我可以像这样使用单个复选框

CheckBox cb = new CheckBox();
cb.setCaptionAsHtml(true);
cb.setCaption("<b> hello </b> there");

但是我无法从CheckBoxGroup访问单个复选框。知道如何访问它们

解决方法

我找到了答案:

                    // 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();
                        }
                    });

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...