How to attach clicklistener to Vaadin label?
Asked Answered
A

2

7

How can I add clicklistener to vaadin label, without putting into horizontal or vertical layout? I want to show tool tip on clicking of the label, not on mouse over.

Alicaalicante answered 15/8, 2017 at 17:11 Comment(0)
P
9

That's not possible.

Putting it in a layout is really not that big of a deal, the following is all you need to do:

HorizontalLayout labelLayout = new HorizontalLayout();
labelLayout.addComponent(new Label("text"));
labelLayout.addLayoutClickListener( e -> <code that does something>);

If you don't want to do that you can use a third party add on which does exactly what you want. https://vaadin.com/directory#!addon/labelbutton

With it you can do:

LabelButton label = new LabelButton("text", event -> <do something>);
Privileged answered 15/8, 2017 at 19:23 Comment(1)
I like the third party add on. That saved my time.Alicaalicante
J
5

I recommend you use a button and add style borderless as shown on the code below. It will appear as a label.

    VerticalLayout vertical = new VerticalLayout();
    vertical.addComponent(new Label("Am the Hint..."));

    PopupView popup = new PopupView(null,vertical);

    Button b = new Button("Show Hint");
    b.addStyleName(ValoTheme.BUTTON_BORDERLESS);
    b.addClickListener((Button.ClickEvent event) -> {
        popup.setPopupVisible(true);
    });
    addComponents(b, popup);
Jessamine answered 15/8, 2017 at 19:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.