Mike Lothar
Mike Lothar

Reputation: 11

GWT clickhandler doesn't hide it's own panel

For a menu implementation, i've added a clickhandler on a FocusPanel, containing a label. Clicking on the FocusPanel opens a VerticalPanel, with several other labels, each with ClickHandlers. Clicking on one of these labels changes the label in the FocusPanel. This part works fine. But for some reason i cannot hide the VerticalPanel after clicking on the label.

Any ideas as to what might be wrong?

I've added some sysout's, which tells me that the panel is in fact hidden, with top location = 0. However, it doesn't dissapear on the screen (tested in FF and Chrome).

final VerticalPanel popupPanel = new VerticalPanel();
    popupPanel.setVisible(false);
    popupPanel.setStyleName("popupGreen");
    for (int i = 0; i < options.length; i++) {
        final Label option = new Label();
        final String text = options[i];
        option.setText(text);
        if (text.equals(chosen)) {
            option.addStyleName("selected");
        }
        option.addClickHandler(new ClickHandler() {

            @Override
            public void onClick(ClickEvent event) {
                textBox.setText(text);
                popupPanel.setVisible(false);
                popupPanel.getElement().getStyle().setProperty("display", "none");
                System.out.println(popupPanel.isVisible());
                System.out.println(popupPanel.getAbsoluteTop());
            }

        });
        popupPanel.add(option);
    }
    verticalPanel.add(popupPanel);

Upvotes: 1

Views: 272

Answers (1)

Thomas Broyer
Thomas Broyer

Reputation: 64541

If the VerticalPanel is within the FocusPanel then the click event will bubble up and the ClickHandler on the FocusPanel will set the VerticalPanel visible again.

Upvotes: 1

Related Questions