Reputation: 172478
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:
Is selection what is commonly known as "OnClick" in other languages/frameworks? Or is there something else that I completely missed?
Upvotes: 9
Views: 9220
Reputation: 36904
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.
Upvotes: 7
Reputation: 497
Yes SelectionListener
is what you are after. I, too, am more of a fan of the OnClick
terminology myself as it is more cut and dry; I digress.
Here is a good example for you to see how it works: http://www.java2s.com/Tutorial/Java/0280__SWT/UsingSelectionListener.htm
Upvotes: 1