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.
How to attach clicklistener to Vaadin label?
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>);
I like the third party add on. That saved my time. –
Alicaalicante
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);
© 2022 - 2024 — McMap. All rights reserved.