GWT inscription as Hyperink

I want a GWT Labelthat acts like a hyperlink.

Basically, the label should have an on click method, which when clicked opens a website. I do not want to implement this with an IFrame.

Is there any way to do this?

Sorry if the issue is pathetically easy to resolve.

+3
source share
1 answer

I would suggest using Anchor, more precisely, through Anchor(java.lang.String text):

Creates a binding for scripts. anchor href installed in javascript: ;; based on the expectation that listeners will be added to the anchor.

So you get a good ol ' <a>that does nothing on click, but you can add to it ClickHandleras 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
    }
});

Anchor Label - , <a>, IMHO. Label, ClickHandler, .

+4

Source: https://habr.com/ru/post/1761610/


All Articles