org.eclipse.swt.widgets.Button click from code

Sergey Kucher picture Sergey Kucher · Jul 6, 2011 · Viewed 10k times · Source

I am trying to click Button from code. I am tying to do the following:

class MyMouseAdapter extends MouseAdapter
{
    public void mouseDown(MouseEvent evt) 
    {
       System.out.println("Working!!!!");
    }
}
Button button = new Button();
button.addMouseListener(new MyMouseAdapter());

now I want to run the mouseDown method from code could you tell me how to do it?

Thank you.

Answer

Mario Marinato picture Mario Marinato · Jul 6, 2011

You can do this:

button.notifyListeners( SWT.MouseDown, null );

Where null is an Event. Remember that this is the Event received by your listener.