flavio.donze flavio.donze - 1 month ago 16
Java Question

Where to set the focus in wizard pages?

I have a

Wizard
containing two wizard pages (
org.eclipse.jface.wizard.WizardPage
) and would like to set the focus for each page separately so that always the top input field of each page is focused.

Setting the focus in
WizardPage.createControl(Composite)
, the first page focus is set correctly. The second page does not have a focus.
This is due to
Wizard.createPageControls(Composite)
which creates all the pages at the beginning.

Where would be the place to handle the focus after switched to the next wizard page?

Answer

Override the WizardPage setVisible method and set focus when the page becomes visible:

@Override
public void setVisible(boolean visible) {
    super.setVisible(visible);

    if (visible) {
       // TODO set focus
    }
}