This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

requestFocus to text field on JInternalFrame not working.

 
rayan alex
Ranch Hand
Posts: 33
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11196
15
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try wrapping the call to request focus inside SwingUtilities#invokeLater.
That way it will request focus after the internal frame is shown
 
rayan alex
Ranch Hand
Posts: 33
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11196
15
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you check out the API doc for the method I mentioned?
 
rayan alex
Ranch Hand
Posts: 33
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes. I referred API.
 
Maneesh Godbole
Saloon Keeper
Posts: 11196
15
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So did it solve the problem?
 
m Korbel
Ranch Hand
Posts: 174
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2989
59
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic