grabFocus() when show JDialog.

Discussion in 'Java' started by Pierre, Sep 2, 2004.

  1. Pierre

    Pierre Guest

    Hello,
    I have a JDialog with a JTextField in my application. When I show the
    dialog, I want the JTextField to grab focus. Very simple... but my
    code doesn't work! the first time I show the dialog the textfield has
    focus, but after it lost it. here an extract of my code :

    public MyDialog(){
    super("test");
    init();
    //search is my JTextField
    search.grabFocus();
    }

    public void show(){
    update();
    search.grabFocus();
    super.show();
    }

    Any idea why this code doesn't work properly ?

    Thanks.
    Pierre.
     
    Pierre, Sep 2, 2004
    #1
    1. Advertising

  2. Pierre

    Paul Lutus Guest

    Pierre wrote:

    > Hello,
    > I have a JDialog with a JTextField in my application. When I show the
    > dialog, I want the JTextField to grab focus. Very simple... but my
    > code doesn't work! the first time I show the dialog the textfield has
    > focus, but after it lost it. here an extract of my code :
    >
    > public MyDialog(){
    > super("test");
    > init();
    > //search is my JTextField
    > search.grabFocus();
    > }
    >
    > public void show(){
    > update();
    > search.grabFocus();
    > super.show();
    > }
    >
    > Any idea why this code doesn't work properly ?


    Use the SwingUtilities.invokeLater() method to request focus, this increases
    the likelihood of success.

    --
    Paul Lutus
    http://www.arachnoid.com
     
    Paul Lutus, Sep 2, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alexandr Molochnikov

    Re: JDialog in taskbar under Linux

    Alexandr Molochnikov, Jul 31, 2003, in forum: Java
    Replies:
    0
    Views:
    1,869
    Alexandr Molochnikov
    Jul 31, 2003
  2. Larry Coon

    Controlling where JDialog opens

    Larry Coon, Oct 23, 2003, in forum: Java
    Replies:
    3
    Views:
    11,229
    Kleopatra
    Oct 24, 2003
  3. venky
    Replies:
    1
    Views:
    3,266
    Chandler
    Nov 13, 2003
  4. cccc
    Replies:
    0
    Views:
    1,838
  5. Anabolik

    show JDialog every 30 seconds

    Anabolik, Nov 4, 2009, in forum: Java
    Replies:
    17
    Views:
    1,342
    Jim Janney
    Nov 5, 2009
Loading...

Share This Page