문제

이제 나는 두 번째 마법사 페이지의 내용을 설정할 수 있습니다. 첫 번째 페이지 선택에서 사용자가 첫 페이지에서 다음 버튼을 클릭 할 때 내 2 페이지의 콘텐츠에 초점을 맞출 수있는 방법을 찾고 있습니다.

기본적으로 사용자가 다음 버튼을 클릭하면 버튼 컴포지트에 중점을 둡니다 (Wizard 구성에 따라 다음, 백 또는 마무리 버튼)

내 페이지의 콘텐츠에 집중하는 유일한 방법은 다음과 같습니다.

public class FilterWizardDialog extends WizardDialog {

    public FilterWizardDialog(Shell parentShell, IWizard newWizard) {
        super(parentShell, newWizard);
    }

    @Override
    protected void nextPressed() {
        super.nextPressed();
        getContents().setFocus();
    }
}

나 에게이 동작을 구현하기 위해 WizardDialog 클래스를 무시 해야하는 것은 약간 "지루하고 무겁다". 더 이상, WizardDialog Javadoc은 다음과 같이 말합니다.

클라이언트는 서브 클래스 할 수 있습니다 WizardDialog, 이것은 거의 필요하지 않습니다.

이 솔루션에 대해 어떻게 생각하십니까? 그 일을 할 수있는 더 쉽고 깨끗한 솔루션이 있습니까?

도움이 되었습니까?

해결책

이것 제안:

마법사 페이지에서 상속 된 것을 사용하십시오 setVisible() 페이지가 표시되기 전에 자동으로 호출되는 메소드가 표시됩니다.

public void setVisible(boolean visible) {
   super.setVisible(visible);
   // Set the initial field focus
   if (visible) {
      field.postSetFocusOnDialogField(getShell().getDisplay());
   }
}

PostSetFocusondialogfield 방법에는 다음이 포함됩니다.

/**
 * Posts <code>setFocus</code> to the display event queue.
 */
public void postSetFocusOnDialogField(Display display) {
    if (display != null) {
        display.asyncExec(
            new Runnable() {
                public void run() {
                    setFocus();
                }
            }
        );
    }
}

다른 팁

Vonc의 답변은 훌륭하게 작동합니다. 개인적으로 이와 같이 작업하기가 조금 더 쉽다는 것을 알았습니다.

@Override
public void setVisible(boolean visible) {
    super.setVisible(visible);
    if (visible) {
        Control control = getControl();
        if (!control.setFocus()) {
            postSetFocus(control);
        }
    }
}

private void postSetFocus(final Control control) {
    Display display = control.getDisplay();
    if (display != null) {
        display.asyncExec(new Runnable() {
            @Override
            public void run() {
                control.setFocus();
            }
        });
    }
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top