Where is the MouseClick event on the SWT button?

I know this sounds like a very simple question, and I feel awkward to ask him, but ...

How to add a mouse cursor to a SWT button?

What I checked:

  • I can find many examples of how to add a mouse, mouse, or double-click (by assigning a MouseListener ). Obviously, a mouse click (a sequence of up and down on the same control) is different from a mouse.
  • I understand that there cannot be a click handler for common controls, but the only event that I see added to Button control is the SelectionListener - it can be, but the selection sounds more like a “received focus” for me than “was pressed or selected, and then called up by pressing the "key.
  • I found a related question , the answer of which basically says that you need to implement this yourself - I find it hard to believe.

Chooses what is commonly called "OnClick" in other languages ​​/ frameworks? Or is there something else that I completely missed?

+6
source share
2 answers

Yes, SWT.Selection or SelectionListener is what you are 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 can be called a choice, because Button can be a checkbox or a radion button depending on the style.

+4
source

Yes SelectionListener is what you need. I'm also a fan of OnClick terminology, as it is more cut and dry; I got distracted.

Here is a good example of how this works: http://www.java2s.com/Tutorial/Java/0280__SWT/UsingSelectionListener.htm

+1
source

Source: https://habr.com/ru/post/972176/


All Articles