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.

1 Year
Discussion Span
Last Post by Saifuddin_1

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) {

    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.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));


    final FocusListener listener = new FocusListener() {

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

        public void focusGained(FocusEvent e) {
            System.out.println("Focus gained");

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

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

        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){


    while (!shell.isDisposed())
        if (!display.readAndDispatch())


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

This article has been dead for over six months. Start a new discussion instead.
Take the time to help us to help you. Please be thoughtful and detailed and be sure to adhere to our posting rules.