This week's book giveaway is in the Reactive Progamming forum.
We're giving away four copies of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams and have Adam Davis on-line!
See this thread for details.
Win a copy of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams this week in the Reactive Progamming forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

JInternalFrame to get Focus

 
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 508
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could try calling requestFocus() on the text field...
 
Sri Rangan
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 508
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot Chantel. It worked.
Sri
 
If we don't do the shopping, we won't have anything for dinner. And I've invited this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!