What is the preferred way for making a label clickable?
I don’t want a button, and I’m aware I can request that a button be styled like a link.
I am essentially looking for the equivalent of a href=“/”, wrapping a label-and-icon pair. For example, if you look at this forum page, the vaadin logo in the upper left hand corner is such a link.
However, I actually want to fire a Vaadin event when a click happens, so, to my newbie eyes, a Link is not the appropriate vehicle here.
Is this where the kind of cool but also kludgy-smelling “clickable layout” comes in?
Lastly, it appears–again to my newbie eyes–that all components have the ability of registering any old event type they want by means of addListener(Class, Object, Method). Would doing something like:
Could you explain what your reasons for not wanting a Button are?
I’d personally most definitely use a Button styled with CSS to look like a label, since the Button already supports click listeners, icons and everything that is needed. Note that the Link component is different from the Button styled as a link.
Another approach is to add a listener to the layout that contains the Label. The LayoutClickListener will provide information about what child component was clicked (provided that the child component does not cancel the event but Label should not do that).
Hello! I want to ask here, not to create a new topic.
I have an annoying problem with LayoutClickListener.
If the user clicks the mouse too often, it is not possible to clear the buffer of events.
And if each click is processed long enough (more than 100 milliseconds), the whole process begins to slow down.
That is a fair question. I have several answers. I don’t claim they’re correct or comprehensive.
The first is just semantics: this isn’t a button. This is an area you click on and then something happens. It’s a region that brings you back to the home page (a common feature on most websites). So a button seemed like a very odd thing to use here, and “hiding” the fact that it’s a button with CSS styling seemed like kind of a hack.
Just out of curiosity: how would a child component cancel an event? I don’t see anything in, for example, MouseEvents.ClickEvent such as, say, cancel().
That would be a built in feature in the client side widget, for instance a Button inside a layout won’t trigger a layoutClick when the Button is clicked.
Yes, that’s true for the Button component, but the NativeButton component is much easier to style (unless you’re after all the fancy states the normal Button provides and want to make them work in all browsers). They’re equal on the server side and functionality, only the presentation is different.
For the clickable label, I’d go with the ClickableLayout, and use CssLayout since it has the least overhead.
I just working the project using vaadin. I plan to use the TextField and PasswodField that user could change the text label by themselves by using right mouse click to that label against the particular field and I shall popup some dialog to allow to change this text. It quit difficult if we have no mouse event listener to do this. The layout listener may be able to to this but It does not work if we using multiple levels of layout to decorate our form. Both open source thinwire and open source Swing have the mouse event listener for all the components but your user interface is much better. I still plan to go ahead with vaadin. If you could incorporate the well designed structure of event listener of thinwire or Swing it should be great.
Any suggest that I could implement this label changeable feature is appreciated.
Thanks
Or Vaadin could just make it possible to get MouseEvent.* off of any component the way swing does so that we can respond to users however we want wherever we want without having to hunt for tricks on the forum or abuse poor little buttons by trying to morph them into all kinds of unnatural things :).
With Vaadin 7 it should be trivial to create an extension that listens to click events and forwards them to the server. See e.g. FileDownloader for an example. You can then attach the extension to any component to get click events (for the whole component).