Fry event on mouseClick in SWT?

The following methods are available in the SWT for the MouseListener interface: mouseUp() , mouseDown() and mouseDoubleClick()

How to trigger an event based on user click?

We can do this by connecting mouseUp() and mouseDown() , but is there a trivial solution in the SWT, such as mouseClick() ?

Thanks.

+4
source share
2 answers

How would a mouse event be defined? Mouse-down followed by a mouse, without a mouse, leaving the bounds of the control (otherwise it will be a drag and drop), right? By this definition, a mouse event cannot be associated with a single point, but rather with a region (1) or a control (2). The first case would not fit in a generic SWT event that only has a location (x and y), and you need additional code to check if the click area is inside your image. In the second case, when the mouse click will be determined only using the control (and no location), this event will be useless to you.

When you embed your own discovery with one click, you can fire any events in the control that you like, even those that are not defined by SWT.

+1
source

To respond to a mouse click event, you can use a SelectionListener, something like this should do the trick:

 button.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { super.widgetSelected(e); System.out.println("click!"); } }); 
0
source

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


All Articles