File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes Focus for a component Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Focus for a component" Watch "Focus for a component" New topic
Author

Focus for a component

selvas kumars
Ranch Hand

Joined: Jan 06, 2001
Posts: 115
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

Joined: Sep 28, 2000
Posts: 508
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

Joined: Jan 09, 2001
Posts: 1492
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Focus for a component