FormPage focusLost Handling

SWT Designer allows you to create the views, editors, perspectives, pref pages, composites, etc. that comprise Eclipse SWT & RCP applications and plug-ins.

Moderators: Konstantin.Scheglov, gnebling, Alexander.Mitin, jwren, Eric Clayberg

FormPage focusLost Handling

Postby derrydavis » Wed Oct 10, 2007 1:01 pm

Hi All,
I've created a formpage and wish to display a pop-up when a user switches focus from the page to another page. I can't seem to get the focusLost event to fire. Thanks in advance for any hints or suggestions. Here's the code snippet that setups the form and the focus events:
Code: Select all
protected void createFormContent(IManagedForm managedForm) {
   FormToolkit toolkit = managedForm.getToolkit();
   ScrolledForm form = managedForm.getForm();
    form.addFocusListener(new FocusAdapter() {
     public void focusGained(FocusEvent e) {
       System.out.println("Form gained focus.");
     public void focusLost(FocusEvent e) {
       System.out.println("Form focus lost!");
        try {
          Shell shell = new Shell();
          MessageDialog.openInformation(shell,"Form pop-up",
   "Form focus was lost.");
        }catch (Error E){
    }catch (Error e){
       System.out.println("Error setting focus listeners! " + e);
Posts: 3
Joined: Mon May 14, 2007 6:19 am

Re: FormPage focusLost Handling

Postby Eric Clayberg » Thu Oct 11, 2007 4:39 am

General SWT questions should be posted to the Eclipse SWT newsgroup.

1. ScrolledForm does not trigger a Focus event (only controls that process
the keyboard can have focus).

2. In any case, you will directly receive a focus gained/lost event only
for the control that gained/lost it; not from all of its parents.

One possible solution - add a focus listener to all the controls on this
ScrolledForm, and in focus lost check that the focus is not in any other
control of this ScrolledForm (i.e., on some other page). You may need to do this in an async block.
Eric Clayberg
Software Engineering Manager

Author: "Eclipse Plug-ins"
Eric Clayberg
Posts: 4503
Joined: Tue Sep 30, 2003 6:39 am
Location: Boston, MA USA

Return to SWT Designer

Who is online

Users browsing this forum: No registered users and 2 guests