Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > grabFocus() when show JDialog.

Reply
Thread Tools

grabFocus() when show JDialog.

 
 
Pierre
Guest
Posts: n/a
 
      09-02-2004
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.
 
Reply With Quote
 
 
 
 
Paul Lutus
Guest
Posts: n/a
 
      09-02-2004
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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
show calendar show clock tony Cisco 1 09-18-2006 07:13 AM
show all files in the directory, but how to show directory control?? strutsng@gmail.com HTML 1 09-30-2005 07:32 AM
TO show or NOT to show Matt ASP .Net 1 05-02-2005 09:07 PM
to show image or to show flash Disco Octopus HTML 7 05-14-2004 06:27 AM
Command "show run" does not show all interfaces Peter Jonas Cisco 3 01-05-2004 12:13 AM



Advertisments