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?
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With