-
Book Overview & Buying
-
Table Of Contents
Google Web Toolkit 2 Application Development Cookbook
By :
In this recipe, we are going to handle ChangeEvent for a CheckBox. When a checkbox is checked or unchecked, the ChangeEvent event fires. This recipe enables and disables a text field when the check box is checked and unchecked, respectively.
Create a form with a CheckBox and a TextField. Name the widgets as otherCheckBox and otherField. Set the box label as Other for the check box.
Write the following code for the recipe:
otherCheckBox.addListener(Events.Change,new Listener<BaseEvent>()
{
@Override
public void handleEvent(BaseEvent be)
{
if(otherCheckBox.getValue())
otherField.enable();
else
otherField.disable();
}
});
The method getValue of CheckBox returns Boolean true when the check box is checked, and false when it is unchecked. If the condition otherCheckBox.getValue() is true, the text field is enabled by calling the enable method of the text field. If the condition is false, the else section will work and disable...
Change the font size
Change margin width
Change background colour