Roger
Roger

Reputation: 4269

Panel onClick handler?

I have a Horizontal Panel, when I click anywhere in that panel, I want a dialog box to pop up. However, there doesn't seem to be a click handler for this panel. Any suggestions? thanks

Upvotes: 1

Views: 626

Answers (2)

Stefan
Stefan

Reputation: 14893

Morning,

you can always add your own Handlers to any panel by calling the addDomHanlder method. The addClickHandler method sim0pliefies that. Here is some sample code for you:

        HorizontalPanel hp = new HorizontalPanel();
    hp.add(new Label("samplelabel 1"));
    hp.add(new Label("samplelabel 2"));
    hp.add(new Label("samplelabel 3"));

    ClickHandler ch = new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            Window.alert("clicked");                
        }
    };

    hp.addDomHandler(ch, ClickEvent.getType());

    hp.setWidth("500px");
    hp.setHeight("500px");

    RootPanel.get().add(hp);

You can read more on the subject under 'Widget Developers' on What's New in GWT 1.6?.

Upvotes: 0

dimchez
dimchez

Reputation: 2004

HorizontalPanel has methods addDomHandler and addHandler which you can use to add ClickHandler, e.g.

HorizontalPanel panel = new HorizontalPanel();
panel.addDomHandler(new ClickHandler() {
    @Override
    public void onClick(ClickEvent event) {
        // TODO process event
    }
}, ClickEvent.getType());

Upvotes: 3

Related Questions