2017-08-15 116 views

回答

1

这是不可能的。

把它在一个布局真的不是什么大不了的事,下面是所有你需要做的:

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

如果你不想这样做,你可以使用一个第三方插件在哪个确实是你想要的。 https://vaadin.com/directory#!addon/labelbutton

有了它,你可以这样做:

LabelButton label = new LabelButton("text", event -> <do something>); 
+0

我喜欢第三方添加。这节省了我的时间。 – user1631306

1

我建议你使用一个按钮,并添加样式无边框下面的代码,如图所示。它将显示为标签。

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);