elaich
elaich

Reputation: 941

widgetDefaultSelected() method never triggered?

Suppose I have two radio buttons, I want one to be default selected, and I want the SelectionListener to do some action.

When I tried the obvious way it didn't work:

Button button = new Button(parent, SWT.RADIO) ;
button.setSelection(true) ;

button.addSelectionListener( new SelectionAdapter() {
    public void widgetDefaultSelected(SelectionEvent e){
        doAction() ;
    }
}) ;

doAction() is never triggered...

Can anybody explain why the SelectionEvent for the default selection is never triggered?

Upvotes: 2

Views: 1222

Answers (2)

Baz
Baz

Reputation: 36894

For example, on some platforms default selection occurs in a List when the user double-clicks an item or types return in a Text. On some platforms, the event occurs when a mouse button or key is pressed. On others, it happens when the mouse or key is released. The exact key or mouse gesture that causes this event is platform specific.

The JavaDoc says it all. It's a platform-dependent action that might occur on some Controls. AFAIK, the Button with SWT.CHECK is not one of them.

Upvotes: 2

Alex Stybaev
Alex Stybaev

Reputation: 4693

change your code to:

button.addSelectionListener( new SelectionAdapter() {
    @Override
    public void widgetSelected(SelectionEvent e){
        doAction() ;
    }
}) ;

and avoid using widgetDefaultSelected().

Upvotes: 1

Related Questions