开发者

Refresh the UI in gwt

I have created some custom composite widget, which listens to an events (in my case loginEvent). Once the event is caught the state of the widget changes so as the way it should look (in my case I w开发者_C百科ould like to change one of the icons to a signal that the user is logged in).

However, after the event is caught, can I make the widget draw itself again according to the new state?

I am pretty new to GWT so be gentle and please elaborate...


There is many ways to do this. This example shows how to show Login/Logout and toggle visibility when a user logged in event is raised.

public class LoginLogoutWidget extends Compostite {
    private final Anchor m_loginLink;
    private final Anchor m_logoutLink;

    public LoginLogoutWidget() {

        m_loginLink = new Anchor("Login");
        //Register event handlers etc

        m_logoutLink = new Anchor("Logout");
        //Register event handlers etc

        HorizontalPanel hp = new HorizontalPanel();

        hp.add(m_loginLink);
        hp.add(m_logoutLink);

        initWidget(hp);

        //Default login visible, and logout invisible
        m_logoutLink.setVisible(false);
    }

    public void onLoginEvent(boolean loggedIn) {        
        m_loginLink.setVisible(!loggedIn);
        m_logoutLink.setVisible(loggedIn);  
    }
}


If you have something like this:

HorizontalPanel panel = new HorizontalPanel();
Image oldImage = new Image("url to old img");
panel.add(oldImage);

Then you should be able to do something like this:

panel.remove(oldImage);
Image newImage = new Image("url to new img");
panel.add(newImage);

panel.layout();

I've found that in some cases, if I don't call the "layout()" method on the parent container, then things that I've added programmatically don't show up on the screen like I expect them to.

Hope that helps!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜