I'm creating a wizard page in eclipse using SWT libraries. So far I have succeeded in creating the page but with only one issue:- SWT composite doesn't get selected. My wizard page contains a scrolledComposite containing multiple composites in a grid fashion. Each composite contains a browser just like a sample template. What i want is when i select a composite containing browser it should get selected and the finish button activated.

Now, my doubt is, how do i make the composite containing the browser selectable as a composite doesn't contain selectionListener. Or better still, is there a way to make a browser selectable?

Sample code would be appreciated.

I'm a noob and this is my first question so please forgive me for any mistakes in question.

I don't think many people here use SWT; it's all Swing or JavaFX. If you don't get any answers soon you may have to look somewhere else. Sorry.

After doing some research, I found there was a system specific bug due to which it wouldn't reach the FocusListener code. See bug here https://bugs.eclipse.org/bugs/show_bug.cgi?id=84532

The following code contains workaround through which a SWT Browser can get focus.

public static void main (String [] args) {

    Display.setAppName("Stackoverflow");
    final Display display = new Display();
    final Shell shell = new Shell(display);

    shell.setSize(500, 400);
    shell.setLayout(new FillLayout());

    final Composite composite = new Composite(shell, SWT.BORDER);
    composite.setLayout(new GridLayout());

    final Browser browser = new Browser(composite, SWT.NONE);
    browser.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

    final Button finish = new Button(shell, SWT.PUSH);
    finish.setText("Finish");
    finish.setEnabled(false);
    finish.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));

    browser.setUrl("google.com");

    final FocusListener listener = new FocusListener() {

        @Override
        public void focusLost(FocusEvent e) {
            System.out.println("Focus lost");
        }

        @Override
        public void focusGained(FocusEvent e) {
            System.out.println("Focus gained");
            finish.setEnabled(true);
        }
    };

    /*
     * workaround for bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=84532
     */
    Listener deactivateListener = new Listener() {

        @Override
        public void handleEvent(Event event) {
            listener.focusLost(new FocusEvent(event));
        }
    };
    Listener activateListener = new Listener() {

        @Override
        public void handleEvent(Event event) {
            listener.focusGained(new FocusEvent(event));
        }
    };

    browser.addListener(SWT.Deactivate, deactivateListener);
    browser.addListener(SWT.Activate, activateListener);

    finish.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e){
            System.out.println("OK");
        }
    });

    shell.open();

    while (!shell.isDisposed())
      {
        if (!display.readAndDispatch())
          display.sleep();
      }
    display.dispose();

}

Now the browser does get focus through which my button gets activated but is there any way to show it as selected?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.