在 Zkoss 中选中的复选框是 setDisabled(true) 但我希望复选框的可见性和勾选保持不变
In Zkoss selected checkbox is setDisabled(true) but i want visibility of checkbox and tick remain same
for(int i=0;i<list_id.size();i++)
{
count++;
Listitem l1=new Listitem();
org.zkoss.zul.Checkbox ccc=new org.zkoss.zul.Checkbox();
l1.setParent(signlist);
Listcell c1=new Listcell();
Listcell c2=new Listcell();
Listcell c3=new Listcell();
c1.setParent(l1);
c2.setParent(l1);
c3.setParent(l1);
c2.setLabel(""+count);
c3.setLabel(getSignId(list_id.get(i),temp));
ccc.setParent(c1);
ccc.setId(list_id.get(i)+":"+i+group_id);
InputStream in =rs.getAsciiStream(2);
StringWriter w = new StringWriter();
IOUtils.copy(in, w);
mapped_sign = w.toString();
if(mapped_sign.contains("|"))
{
list_Name=mapped_sign.split("\|");
for(int k=0;k<list_Name.length;k++)
{
list_id_Check.add(list_Name[k]);
}
if(list_id_Check.contains(list_id.get(i)))
{
ccc.setChecked(true);
}
}
else
{
if(list_id.get(i).equals(mapped_sign))
{
ccc.setChecked(true);
}
}
ccc.setDisabled(true);
c3.setId(list_id.get(i)+":"+group_id);
}
当我应用 setDisabled(true) 时,选中和未选中的复选框可见性消失。我只想在应用 setDisabled 后复选框和勾选的可见性仍然保持不变。
据我所知,没有特定于 ZK 的方法来做到这一点。
不过,您可以使用普通的 CSS(也可能是自定义复选框精灵)来设置您自己的复选框的样式。
这是一个example (CSS taken from https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Forms/Advanced_styling_for_HTML_forms)
<zk>
<window border="normal" title="hello">
<style>
:root input[type=checkbox] {
/* original check box are push outside the viexport */
position: absolute;
left: -1000em;
}
:root input[type=checkbox] + label:before {
content: "";
display: inline-block;
width : 16px;
height : 16px;
margin : 0 .5em 0 0;
background: url("https://developer.mozilla.org/files/4173/checkbox-sprite.png") no-repeat 0 0;
/* The following is used to adjust the position of
the check boxes on the text baseline */
vertical-align: bottom;
position: relative;
bottom: 2px;
}
:root input[type=checkbox]:checked + label:before {
background-position: 0 -16px;
}
</style>
<vlayout>
<checkbox id='chk1' label='enabled' />
<checkbox id='chk2' label='disabled unchecked' disabled='true' />
<checkbox id='chk3' label='disabled checked' checked='true' disabled='true' />
</vlayout>
</window>
</zk>
当然,您不应该 link mozilla 的 sprite,而是提供您自己的。
这是一个提供更多 link 和示例的 SO 答案:How to style checkbox using CSS?
for(int i=0;i<list_id.size();i++)
{
count++;
Listitem l1=new Listitem();
org.zkoss.zul.Checkbox ccc=new org.zkoss.zul.Checkbox();
l1.setParent(signlist);
Listcell c1=new Listcell();
Listcell c2=new Listcell();
Listcell c3=new Listcell();
c1.setParent(l1);
c2.setParent(l1);
c3.setParent(l1);
c2.setLabel(""+count);
c3.setLabel(getSignId(list_id.get(i),temp));
ccc.setParent(c1);
ccc.setId(list_id.get(i)+":"+i+group_id);
InputStream in =rs.getAsciiStream(2);
StringWriter w = new StringWriter();
IOUtils.copy(in, w);
mapped_sign = w.toString();
if(mapped_sign.contains("|"))
{
list_Name=mapped_sign.split("\|");
for(int k=0;k<list_Name.length;k++)
{
list_id_Check.add(list_Name[k]);
}
if(list_id_Check.contains(list_id.get(i)))
{
ccc.setChecked(true);
}
}
else
{
if(list_id.get(i).equals(mapped_sign))
{
ccc.setChecked(true);
}
}
ccc.setDisabled(true);
c3.setId(list_id.get(i)+":"+group_id);
}
当我应用 setDisabled(true) 时,选中和未选中的复选框可见性消失。我只想在应用 setDisabled 后复选框和勾选的可见性仍然保持不变。
据我所知,没有特定于 ZK 的方法来做到这一点。
不过,您可以使用普通的 CSS(也可能是自定义复选框精灵)来设置您自己的复选框的样式。
这是一个example (CSS taken from https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Forms/Advanced_styling_for_HTML_forms)
<zk>
<window border="normal" title="hello">
<style>
:root input[type=checkbox] {
/* original check box are push outside the viexport */
position: absolute;
left: -1000em;
}
:root input[type=checkbox] + label:before {
content: "";
display: inline-block;
width : 16px;
height : 16px;
margin : 0 .5em 0 0;
background: url("https://developer.mozilla.org/files/4173/checkbox-sprite.png") no-repeat 0 0;
/* The following is used to adjust the position of
the check boxes on the text baseline */
vertical-align: bottom;
position: relative;
bottom: 2px;
}
:root input[type=checkbox]:checked + label:before {
background-position: 0 -16px;
}
</style>
<vlayout>
<checkbox id='chk1' label='enabled' />
<checkbox id='chk2' label='disabled unchecked' disabled='true' />
<checkbox id='chk3' label='disabled checked' checked='true' disabled='true' />
</vlayout>
</window>
</zk>
当然,您不应该 link mozilla 的 sprite,而是提供您自己的。
这是一个提供更多 link 和示例的 SO 答案:How to style checkbox using CSS?