Hi I use GWT and I have a com.smartgwt.client.widgets.Button that has the following eventHandler:
Button viewCommentsButton = new Button("View ");
viewCommentsButton.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
if (!childrenVisible) {
addChildren();
getParent().setTitle("Close");
} else {
removeChildren();
getParent().setTitle("View");
}
}
});
As you can see I tried getParent().setTitle() method but with no effect. The if works fine so I guess I can’t get the reference to my button object but the code compiles and getParent returns a widget so most likely my button.
However, the addChildren and removeChildren methods are working properly but my button has the initial title all the time. Any ideas why? Hope this makes sense.
Any suggestions are welcomed. Thanks.
If you are trying to set the title on
viewCommentsButton, callviewCommentsButton.setTitle().If you are trying to set the text in the button, call
viewCommentsButton.setText().For either of these you’ll have to mark the button as final – declare it with
final Button viewCommentsButton = ...The context of
getParent()is confusing.getParent(), the way you’re using it, will return the parent of the widget in which you’re defining all of this, NOT the parent ofviewCommentsButtonand definitely notviewCommentsButtonitself.