Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java SWT: widgetSelected vs widgetDefaultSelected

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?

like image 757
Jiew Meng Avatar asked Feb 13 '12 00:02

Jiew Meng


People also ask

What is the difference between widgetdefaultselected and widgetselected?

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.

What is the difference between swing and SWT?

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.

What is the difference between Eclipse and SWT?

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.

What is the Javadoc for the selection event?

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.


1 Answers

Use widgetSelected. In fact, all the better is to simply extend SelectionAdapter and only override the widgetSelected method and completely ignore widgetDefaultSelected.

like image 178
Edward Thomson Avatar answered Nov 15 '22 11:11

Edward Thomson