1

I'm struggeling with the SWT Events.

Is there a way to get notified when a Combo is closed? I need to know when it is closed and the selection didn't changed.

I noticed that there is an event type SWT.Collapse, but as far as I know this only for TreeItems (http://book.javanb.com/swt-the-standard-widget-toolkit/ch01lev1sec3.html)

I would be pleased if someone can give me an hint

0

1 Answer 1

2

You can find the list of available Events for a given Widget on the Javadoc page. The Events for Combo are:

Events:

DefaultSelection, Modify, Selection, Verify, OrientationChange

If you are just looking for a way to find out if a new item was selected, just listen for SWT.Selection and compare it to the last selected item. SWT.Selection is only called when an item actually is selected, not if the Combo is opened and then closed by loosing the focus:

combo.addListener(SWT.Selection, new Listener()
{
    @Override
    public void handleEvent(Event arg0)
    {
        String currentSelection = combo.getItem(combo.getSelectionIndex());
        
        if(currentSelection.equals(oldSelection))
        {
            // Same item selected
        }
        else
        {
            // Different item selected
        }

        oldSelection = currentSelection;
    }
});

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.