Vaadin Web应用开发教程(16):UI组件-Checkbox
上一篇:http://www.zzzyk.com/kf/201208/146780.html
Checkbox 的状态可以为checked和unchecked. 其值可以通过getValue, setValue 来操作。基本用法如下
[java]
// A check box with default state (not checked, false).
final CheckBox checkbox1 = new CheckBox("My CheckBox");
main.addComponent(checkbox1);
// Another check box with explicitly set checked state.
final CheckBox checkbox2 = new CheckBox("Checked CheckBox");
checkbox2.setValue(true);
main.addComponent(checkbox2);
// Make some application logic. We use anonymous listener
// classes here. The above references were defined as final
// to allow accessing them from inside anonymous classes.
checkbox1.addListener(new ValueChangeListener() {
public void valueChange(ValueChangeEvent event) {
// Copy the value to the other checkbox.
checkbox2.setValue(checkbox1.getValue());
}
});
checkbox2.addListener(new ValueChangeListener() {
public void valueChange(ValueChangeEvent event) {
// Copy the value to the other checkbox.
checkbox1.setValue(checkbox2.getValue());
}
});
checkbox1.setImmediate(true);
checkbox2.setImmediate(true);
// A check box with default state (not checked, false).
final CheckBox checkbox1 = new CheckBox("My CheckBox");
main.addComponent(checkbox1);
// Another check box with explicitly set checked state.
final CheckBox checkbox2 = new CheckBox("Checked CheckBox");
checkbox2.setValue(true);
main.addComponent(checkbox2);
// Make some application logic. We use anonymous listener
// classes here. The above references were defined as final
// to allow accessing them from inside anonymous classes.
checkbox1.addListener(new ValueChangeListener() {
public void valueChange(ValueChangeEvent event) {
// Copy the value to the other checkbox.
checkbox2.setValue(checkbox1.getValue());
}
});
checkbox2.addListener(new ValueChangeListener() {
public void valueChange(ValueChangeEvent event) {
// Copy the value to the other checkbox.
checkbox1.setValue(checkbox2.getValue());
}
});
checkbox1.setImmediate(true);
checkbox2.setImmediate(true);
Checkbox除了单独使用之外,还可以应用到OptionGroup 和Tabel中,具体参见后续文章。
作者:mapdigit
补充:Web开发 , 其他 ,