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 JInternalFrame to get Focus Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JInternalFrame to get Focus" Watch "JInternalFrame to get Focus" New topic
Author

JInternalFrame to get Focus

Sri Rangan
Ranch Hand

Joined: Dec 08, 2001
Posts: 160
Starting class my application is a JFrame. When the JFrame is kicked off, it will open a JinternalFrame. JFrame will stay through out the application. When the JInternalFrame is opened, it does not have the focus. User has to explicitly click the first JTextField. How to I get the default focus on the first Component on the JInternalFrame.
Thanks
Sri
Chantal Ackermann
Ranch Hand

Joined: Sep 28, 2000
Posts: 508
Is your JFrame using a JDesktopPane? it should. this class has a method setSelectedFrame(JInternalFrame). this will activate the given internal frame.
but I think, the default behaviour is that the newly opened JInternalFrame gets the focus. and normally (my experience) the first textfield gets the focus inside the focused frame.
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

You could try calling requestFocus() on the text field...


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Sri Rangan
Ranch Hand

Joined: Dec 08, 2001
Posts: 160
I tried both setSelectedFrame() as well requestFocus(). Still not working.
My JFrame code to open JinternalFrame

My Logon form code to regquestFocus()

Waht is going wrong here? Still I have to click on the logon form to get the focus
Thanks
Sri
Chantal Ackermann
Ranch Hand

Joined: Sep 28, 2000
Posts: 508
you can only request focus after the frame is really visible on the screen. any requests before that won't have effect. if you don't know when this is, attach an ancestorlistener to the frame and catch the event 'ancestorAdded'.
Sri Rangan
Ranch Hand

Joined: Dec 08, 2001
Posts: 160
Thanks a lot Chantel. It worked.
Sri
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JInternalFrame to get Focus