Where is the MouseClick event on an SWT Button?
button, java, swt
Solution
Yes, `SWT.Selection` or `SelectionListener` is what you're looking for:
Button button = new Button(shell, SWT.PUSH);
button.addListener(SWT.Selection, new Listener()
{
@Override
public void handleEvent(Event event)
{
System.out.println("SWT.Selection");
}
});
adding a `SelectionListener` internally does the same as the code above.
It might be called selection, because a `Button` can be a checkbox or a radion button depending on it's style.
Problem
I know this sounds like a very basic question, and I feel embarrassed to ask it but... How to I add a Mouse Click handler to an SWT button? What I checked: - I can find tons of examples on how to add mouse down, mouse up or double click handlers (by assigning a MouseListener). Obviously, mouse click (sequence of down and up on the same control) is something different than mouse down. - I understand that there might not be a click handler on generic controls, but the only event I see added on the Button control is a SelectionListener -- that might be it, but selection sounds more like "received focus" to me than "was clicked or selected and then invoked with a key press". - I found a related question, whose answer basically says that you need to implement that yourself -- I find that a bit hard to believe. Is selection what is commonly known as "OnClick" in other languages/frameworks? Or is there something else that I completely missed?