Hi Michael,

I created a snippet (see at the end of the mail) as described by you and it
worked correctly.

Which version of ULC are you using?

Could you modify the attached snippet to demonstrate the problem and send it
to me?

Thanks and regards,

Janak

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] Behalf Of Brohl Michael
Sent: Wednesday, May 10, 2006 2:39 PM
To: [email protected]
Subject: [ULC-developer] how to set focus on a specified component?


Hi,

I try to set the focus to a specified component when showing a dialog. The
dialog consists of a toolbar and a content pane with several other panes
containing the components.

I have a show() method in the dialog which looks like this:

    public void show() {
        this.setVisible(true);
    }

I added a line to request the focus on a text field:

    public void show() {
        this.setVisible(true);
        getDocumentPane().getSupplierPane().grabFocus();
    }

The supplier pane has the method grabFocus() which looks like this:

    public void grabFocus() {
        getSupplierIdTextField().requestFocus();
    }

This is to avoid making the text fields public and to make the supplier pane
control the grabbing of the focus (the pane is reused in several dialogs).

Unfortunately, this does not work :-) The dialog is shown but the focus is
on the first button of my toolbar instead of the textfield.

Am I missing something?

Thanks and regards,

Michael

--------------------

import com.ulcjava.base.application.AbstractAction;
import com.ulcjava.base.application.AbstractApplication;
import com.ulcjava.base.application.BorderFactory;
import com.ulcjava.base.application.IAction;
import com.ulcjava.base.application.ULCBoxPane;
import com.ulcjava.base.application.ULCButton;
import com.ulcjava.base.application.ULCDialog;
import com.ulcjava.base.application.ULCFrame;
import com.ulcjava.base.application.ULCLabel;
import com.ulcjava.base.application.ULCTextField;
import com.ulcjava.base.application.ULCToolBar;
import com.ulcjava.base.application.ULCWindow;
import com.ulcjava.base.application.event.ActionEvent;
import com.ulcjava.base.development.DevelopmentRunner;

public class FocusInDlgSnippet extends AbstractApplication {
    public void start() {
        ULCBoxPane content = new ULCBoxPane(true);
        content.add(new ULCButton(new ButtonAction()));

        ULCFrame frame = new ULCFrame("FocusInDlgSnippet");
        frame.setDefaultCloseOperation(ULCFrame.TERMINATE_ON_CLOSE);
        frame.add(content);
        frame.setSize(200,100);
        frame.setVisible(true);
    }

    private static class ButtonAction extends AbstractAction {
        public ButtonAction() {
            putValue(IAction.NAME, "Show dialog");
        }

        public void actionPerformed(ActionEvent event) {
           MyDialog d = new MyDialog();
           d.show();
        }
    }

    public static void main(String[] args) {
        DevelopmentRunner.setApplicationClass(FocusInDlgSnippet.class);
        DevelopmentRunner.main(args);
    }

    public static class MyDialog extends ULCDialog {
        private MyPanel1 panel1;
        private MyPanel2 panel2;

        public MyDialog() {
                setDefaultCloseOperation(ULCWindow.DISPOSE_ON_CLOSE);
                ULCBoxPane content = new ULCBoxPane(true);
                ULCToolBar toolBar = new ULCToolBar();
                toolBar.add(new ULCButton("Tool1"));
                toolBar.add(new ULCButton("Tool2"));
                toolBar.add(new ULCButton("Tool3"));

                content.add(ULCBoxPane.BOX_EXPAND_CENTER, toolBar);

                panel1 = new MyPanel1();
                content.add(panel1);
                panel2 = new MyPanel2();
                content.add(panel2);
                setContentPane(content);
                setDefaultButton(panel1.getButton());
        }

                public void show() {
                        setVisible(true);
                        panel2.grabFocus();
                }
    }

    public static class MyPanel1 extends ULCBoxPane {
        private ULCButton button;
        public  MyPanel1() {
                setColumns(1);
                add(button = new ULCButton("Button"));
                add(new ULCTextField(20));
                setBorder(BorderFactory.createTitledBorder("Panel1"));
        }
                public ULCButton getButton() {
                        return button;
                }
                public void grabFocus() {
                button.requestFocus();
        }

    }

    public static class MyPanel2 extends ULCBoxPane {
        private ULCTextField text;

        public MyPanel2() {
                setColumns(1);
                add(new ULCLabel("Text"));
                add(text = new ULCTextField(20));
                setBorder(BorderFactory.createTitledBorder("Panel2"));
        }

        public void grabFocus() {
                text.requestFocus();
        }
    }
}

_______________________________________________
ULC-developer mailing list
[email protected]
http://lists.canoo.com/mailman/listinfo/ulc-developer

Reply via email to