tags:

views:

499

answers:

2

I've created a dialog class filling some common widgets, like text, combo, and tree. It annoys to have the default behavior to dismiss this dialog (same as the default 'OK' button is pressed) when enter/return is pressed whichever widget I was in.

To prevent this behavior, I have to add a traverse listener for each widget to filter the traverse key:

if (SWT::TRAVERSE_RETURN == event.detail) {
  event.doit = false 
}

This is somewhat annoying. Is there a way to globally do in the dialog level?

A: 

According to this thread, this seems to be the only way, also illustrated by Snippet127 ("prevent Tab from traversing out of a control")

May be this Dialog class illustrates a global use of a TraverseListener with their keyTraversed() method.

VonC
Just experimented with implementing TraverseListener in the dialog class, but it turns out the event would go to individual widget first, then 'maybe' go to the containing dialog (not sure, since I can't observe this behavior). Anyway, globally defining in dialog class doesn't seem to be a solution.
bryantsai
A: 

You could probably set the default button to null (Shell#setDefaultButton(null)) to prevent the behaviour for the complete dialog, otherwise I guess you'll have to single out the widgets where you want to supress the Enter key.

Kire Haglin