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. Advertisements

  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. Advertisements

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. Matt

    TO show or NOT to show

    Matt, May 2, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    529
  2. Disco Octopus

    to show image or to show flash

    Disco Octopus, May 13, 2004, in forum: HTML
    Replies:
    7
    Views:
    2,646
    Toby A Inkster
    May 14, 2004
  3. Replies:
    1
    Views:
    774
    Evertjan.
    Sep 30, 2005
  4. Anabolik

    show JDialog every 30 seconds

    Anabolik, Nov 4, 2009, in forum: Java
    Replies:
    17
    Views:
    1,505
    Jim Janney
    Nov 5, 2009
  5. Replies:
    1
    Views:
    308
    Evertjan.
    Sep 30, 2005
  6. Roedy Green
    Replies:
    5
    Views:
    2,968
    Gene Wirchenko
    Dec 13, 2011
  7. Gerald Bauer
    Replies:
    0
    Views:
    429
    Gerald Bauer
    Aug 26, 2008
  8. nick
    Replies:
    3
    Views:
    591
    Grant Wagner
    Jun 15, 2004
Loading...