aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes requestFocus to text field on JInternalFrame not working. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "requestFocus to text field on JInternalFrame not working. " Watch "requestFocus to text field on JInternalFrame not working. " New topic
Author

requestFocus to text field on JInternalFrame not working.

rayan alex
Ranch Hand

Joined: Nov 25, 2012
Posts: 33
    
    1
Hi,
I have MDI form with few Internal Frames. I want to set request focus to one of the text fields when Internal frame is opening. I tried to use requestFocus() method and requestFocusInWindow() method.
Non of them worked for me. I have this problem only with JInternal Frames. I called both methods on constructor.
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10451
    
    8

Try wrapping the call to request focus inside SwingUtilities#invokeLater.
That way it will request focus after the internal frame is shown


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
rayan alex
Ranch Hand

Joined: Nov 25, 2012
Posts: 33
    
    1
Hi Maneesh. Thanks lot for your reply. Could you explain little more how to do that. I havent done that before. Im new to Java yet. please
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10451
    
    8

Did you check out the API doc for the method I mentioned?
rayan alex
Ranch Hand

Joined: Nov 25, 2012
Posts: 33
    
    1
Yes. I referred API.
Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10451
    
    8

So did it solve the problem?
m Korbel
Ranch Hand

Joined: Jun 19, 2012
Posts: 155
I referred API, probably not, have to read description about requestFocusInWindow()

public void requestFocus()

Requests that this Component gets the input focus. Refer to Component.requestFocus() for a complete description of this method.

Note that the use of this method is discouraged because its behavior is platform dependent. Instead we recommend the use of requestFocusInWindow(). If you would like more information on focus, see How to Use the Focus Subsystem, a section in The Java Tutorial.
Tony Docherty
Bartender

Joined: Aug 07, 2007
Posts: 2310
    
  49
@m Korbel: Please don't use bold text throughout your post, it comes across as shouting. If you are quoting from a source and want to make it stand out then you could wrap the quoted text in quote tags or use italics.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: requestFocus to text field on JInternalFrame not working.