For example I want to execute something when user clicks on a button. Which do I use? The documentation didn't appear to make it very clear
UPDATE
A quick test shows that Widget Selected is triggered but not Default Selected.
In TasksView.main()
TasksView view = new TasksView(shell, SWT.None);
TasksController controller = new TasksController(view);
In TasksController
public class TasksController extends ControllerAbstract {
protected TasksView view;
public TasksController(TasksView view) {
this.view = view;
view.addTaskListener(new AddTaskListener());
}
protected class AddTaskListener implements SelectionListener {
@Override
public void widgetDefaultSelected(SelectionEvent arg0) {
System.out.println("Default Selected");
}
@Override
public void widgetSelected(SelectionEvent arg0) {
System.out.println("Widget Selected");
}
}
}
btw, Did I do MVC correctly?
The javadoc says "widgetSelected is called when the user changes the control's value. widgetDefaultSelected is typically called when ENTER is pressed. " Thanks for the hint, I was looking at an outdated SWT version. My intention was to prove that the meaning and existance of either two events is widget specific.
Since Swing is built on AWT and provides a pluggable look and feel, Swing should have all the layout managers of AWT. This may make the problem a little more complicated than SWT. SWT is a complete system by itself and there is no need to refer to other libraries. This may be another advantage of SWT over Swing.
As Eclipse is a proven successful framework for extensible software development, SWT is a good choice since they are more compatible with each other. If you want someone to read your code, please put the code inside <pre><code> and </code></pre> tags. For example: We were unable to load Disqus Recommendations.
The javadoc is as follows: void org.eclipse.swt.events.SelectionListener.widgetSelected(SelectionEvent e) Sent when selection occurs in the control. For example, selection occurs in a List when the user selects an item or items with the keyboard or mouse.
Use widgetSelected
. In fact, all the better is to simply extend SelectionAdapter
and only override the widgetSelected
method and completely ignore widgetDefaultSelected
.
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