Monday, June 1, 2009

Button.click() not working


Problem


When calling the method Button.click () (class of GWT) nothing happens. Ex:

...
Button button = new Button ( "Button");

button.addClickHandler (new ClickHandler () (
@ Override
public void onClick (ClickEvent event) (
throw new RuntimeException ( "RuntimeException");
)));

button.click ();
...

This code, in principle, should launch an exception.

Reason

The button, or an object that contains it, was not added to RootPanel.

Solution

Add the widget to RootPanel. Ex:

...
Button button = new Button ( "Button");

RootPanel.get (). Add (button);

button.addClickHandler (new ClickHandler () (
@ Override
public void onClick (ClickEvent event) (
throw new RuntimeException ( "RuntimeException");
)));

button.click ();
...

More:


No comments:

Post a Comment