瀏覽代碼

BoV: Components/Button,CheckBox: Listener API updates

Change-Id: I266bf780d24e411b17d449ff5f9ce880fad53d36
feature/eventbus
Johannes Dahlström 8 年之前
父節點
當前提交
f4965d9b93

+ 7
- 15
documentation/components/components-button.asciidoc 查看文件



The [classname]#Button# component is normally used for initiating some action, The [classname]#Button# component is normally used for initiating some action,
such as finalizing input in forms. When the user clicks a button, a such as finalizing input in forms. When the user clicks a button, a
[classname]#Button.ClickEvent# is fired, which can be handled with a
[interfacename]#Button.ClickListener# in the [methodname]#buttonClick()# method.
[classname]#Button.ClickEvent# is fired, which can be handled by adding a __click listener__
using either the [methodname]#onClick()# or the [methodname]#addClickListener()# method.


You can handle button clicks with an anonymous class as follows: You can handle button clicks with an anonymous class as follows:


---- ----
Button button = new Button("Do not press this button"); Button button = new Button("Do not press this button");


button.addClickListener(new Button.ClickListener() {
public void buttonClick(ClickEvent event) {
Notification.show("Do not press this button again");
}
});

// Java 8
button.addClickListener(click ->
button.addClickListener(clickEvent ->
Notification.show("Do not press this button again")); Notification.show("Do not press this button again"));
---- ----
See the http://demo.vaadin.com/book-examples-vaadin7/book#component.button.basic[on-line example, window="_blank"]. See the http://demo.vaadin.com/book-examples-vaadin7/book#component.button.basic[on-line example, window="_blank"].
.Button in Different Styles of Valo Theme .Button in Different Styles of Valo Theme
image::img/button-example1.png[width=70%, scaledwidth=100%] image::img/button-example1.png[width=70%, scaledwidth=100%]


If you handle several buttons in the same listener, you can differentiate
between them either by comparing the [classname]#Button# object reference
returned by the [methodname]#getButton()# method of
[classname]#Button.ClickEvent# to a kept reference. For a detailed description
of these patterns together with some examples, please see
If you handle several buttons in the same listener, you can differentiate between
them by comparing the [classname]#Button# object reference returned by the [methodname]#getButton()#
method of [classname]#Button.ClickEvent# to a kept reference. For a detailed description
of these patterns together with some examples, please see
<<dummy/../../../framework/architecture/architecture-events#architecture.events,"Events and Listeners">>. <<dummy/../../../framework/architecture/architecture-events#architecture.events,"Events and Listeners">>.


== CSS Style Rules == CSS Style Rules

+ 6
- 8
documentation/components/components-checkbox.asciidoc 查看文件

selection mode, as described in selection mode, as described in
<<dummy/../../../framework/components/components-optiongroup#components.optiongroup,"OptionGroup">>. <<dummy/../../../framework/components/components-optiongroup#components.optiongroup,"OptionGroup">>.


Clicking on a check box will change its state. The state is a
[classname]#Boolean# property that you can set with the [methodname]#setValue()#
method and obtain with the [methodname]#getValue()# method of the
[classname]#Property# interface. Changing the value of a check box will cause a
[classname]#ValueChangeEvent#, which can be handled by a
[classname]#ValueChangeListener#.
Clicking on a check box will change its state. The state is a [classname]#Boolean#
property that you can set with the [methodname]#setValue()# method and obtain with
the [methodname]#getValue()# method. Changing the value of a check box will cause
a [classname]#ValueChangeEvent#, which can be handled by a [classname]#ValueChangeListener#.




[source, java] [source, java]


checkbox2.setValue(true); checkbox2.setValue(true);


checkbox1.addValueChangeListener(event -> // Java 8
checkbox1.addValueChangeListener(event ->
checkbox2.setValue(! checkbox1.getValue())); checkbox2.setValue(! checkbox1.getValue()));


checkbox2.addValueChangeListener(event -> // Java 8
checkbox2.addValueChangeListener(event ->
checkbox1.setValue(! checkbox2.getValue())); checkbox1.setValue(! checkbox2.getValue()));
---- ----



Loading…
取消
儲存