开发者

setFocus() always false

开发者 https://www.devze.com 2022-12-18 10:27 出处:网络
I\'m working on a Eclipse RCP Appli开发者_如何学Pythoncation. In a class which extends MultiPageEditorPart, I\'m trying to set the focus to a text field. But the setFocus Method always returns false.

I'm working on a Eclipse RCP Appli开发者_如何学Pythoncation. In a class which extends MultiPageEditorPart, I'm trying to set the focus to a text field. But the setFocus Method always returns false.

What am I doing wrong?

The MultiPageEditor has various pages and inside these pages, there are Composite - classes. These classes contain the text field.

Here is the snippet: (errorPage is an int, the Pagenumber on which my validation found the error)

if(!dataValid) {
   MessageDialog.openError(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), "Fehler bei der Dateneingabe", stringBuilder.toString());
   this.setActivePage(errorPage);
   Composite errorComposite = (Composite) this.getControl(errorPage);
   Control[] children = errorComposite.getChildren();
   for (Control child : children) {
    if(child instanceof Form) {
     Form form = (Form) child;
     Composite body = form.getBody();
     Control[] formChildren = body.getChildren();
     for (Control formChild : formChildren) {
      if(formChild.equals(errorControl)) 
                            formChild.setFocus();
      return dataValid;
     } 
    }
   }
  }


The setFocus() may return false on the following situations:

  1. Maybe control is a unfocusable control like Label
  2. Composites attempt to assign focus to their children before taking focus themselves
  3. A control will not take focus if it is disabled or hidden
  4. Input is blocked due to modality.

So I would better check, (1) am I setting focus on the right control, (2) is the control visible, maybe the form containing the control is not in the current selected tab. (3) is any other modal dialog open.


Have you tried Control#forceFocus()?

0

精彩评论

暂无评论...
验证码 换一张
取 消