[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.platform.swt] Re: JFace Dialog - change default focus

Joe Gagnon wrote:
We have a situation in our project where we display a dialog (using a JFace Dialog) and we want to change the default focus from the OK/Cancel buttons to a button (or other widget type) on the "body" of the dialog. The "body" is implemented as a SWT Composite. Creating a Composite that contains all of the widgets for a given screen has been the approach we've been using for screens in general. This way we can place the composite on any container (dialog, wizard, editor tab, etc.).

The reason we need to do this is that the user community that will end up using this will tend to hit Enter/Return on their keyboards to move from field to field on the screens. (They have been accustomed to using terminal-based applications and hitting Return is how they enter data and navigate through a screen's fields.) If they do this on dialogs, the will trigger the OK button and end up closing the window.

Any ideas on how to shift the focus to where we need it, -or- some other solution?

What you need to do is override the traversal events on your form. This can be done using a SWT.Traverse event filter. Be aware that event filtering can slow down your application if you're not careful, so try to keep your listeners lean.


display.addFilter(SWT.Traverse, new Listener() {
  public void handleEvent(Event event) {
    if (event.detail == SWT.TRAVERSE_RETURN &&
        shouldOverrideDefaultTraversal(event.widget))
      event.detail = SWT.TRAVERSE_TAB_NEXT;
  }
});

I'm not positive this will work but you can always try. Make sure to remove the filter when the user closes the dialog.

Matthew