Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

java

swt

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.

like image 903
Sergey Kucher Avatar asked Jul 06 '11 11:07

Sergey Kucher


2 Answers

You can do this:

button.notifyListeners( SWT.MouseDown, null );

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

like image 147
Mario Marinato Avatar answered Nov 15 '22 17:11

Mario Marinato


If you need all the listeners to be notified then you can try the below code,

yourbutton.notifyListeners(SWT.Selection, new Event());
like image 20
Melwyn Jensen Avatar answered Nov 15 '22 17:11

Melwyn Jensen