tags:

views:

40

answers:

1

Hi

I want a Gwt Label which acts like an hyperlink.

Basically the label should have an on click method which when clicked opens up a website.I dont want to implement this using an IFrame.

Is there any way i can do this?

Soryy if the question is pathetically easy to solve.

+1  A: 

I'd suggest using Anchor, more specifically, via the Anchor(java.lang.String text) constructor:

Creates an anchor for scripting. The anchor's href is set to javascript:;, based on the expectation that listeners will be added to the anchor.

So, you'll get a good ol' <a> that on click doesn't do anything, but you can add a ClickHandler to it, as such:

Anchor anchor = new Anchor("Click me!"); // At this point clicking it won't do a thing
anchor.addClickHandler(new ClickHandler() {
    @Override
    public void onClick (ClickEvent event){
        Window.open("http://www.example.com/", "_blank", ""); // Or open a PopupPanel
                                                              // or sth similar
    }
});

I'm advising Anchor over Label for accessibility reasons - if it's a link, then it should be an <a>, IMHO. If you really need to use a Label, you can add to it a ClickHandler like shown above.

Igor Klimer