Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to attach clicklistener to Vaadin label?

Tags:

label

vaadin

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.

like image 662
user1631306 Avatar asked Aug 15 '17 17:08

user1631306


2 Answers

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>);
like image 100
Oleg Avatar answered Nov 07 '22 15:11

Oleg


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);
like image 39
Dun0523 Avatar answered Nov 07 '22 15:11

Dun0523