This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Focus for a component

 
selvas kumars
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I want the focus to be in a specified comp when the screen
comes up.i tried using below methods..I am unable to get the focus for the desired one..how to go about??
setRequestFocusEnabled(true);
requestFocus();
requestDefaultFocus() ;
Thanks,
silva.
 
Chantal Ackermann
Ranch Hand
Posts: 508
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
I found that at JGuru:
"The requestFocus() method will only work when the component is visible so ensure that your window/applet is visible and that your component has been added to it. Then call the requestFocus() method on the component to switch the focus."
i've seen in the API a method setInitialFocus(). Maybe that will work?!
chantal
 
Manfred Leonhardt
Ranch Hand
Posts: 1492
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Selvas,
You have 2 choices:
1. Immediately after using frame.setVisible( true ) place your requestFocus call:

or
2. Register your component to listener for itself as a ComponentListener. Override the componentShown method and request the focus there:

Regards,
Manfred.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic