Win a copy of Murach's MySQL this week in the JDBC and Relational Databases 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Losing focus after bringing another window into focus

 
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
JDK 1.3:

I have a JPanel. Focus, in this panel, could be on a JButton or JTextField. But if I bring into focus another browser window and revert back to JPanel, the JButton or JTextField doesn't have the focus any more!

Could somebody explain why this happens and what could be done to prevent this from happening so the component retains it's focus.

Thanks.
 
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i've had similar probs, but i'm using 1.4.x. some probs were related to bizarre behavior following a load of window events

i don't know why the focus is lost - there have been several focus mods to awt and swing, and focus defaults are also influenced by platform (esp pre 1.4)...

have you tried

requestFocus (1.3)
requestFocusInWindow (1.4)

on the component(s) in question? (you would need to invoke requestFocus/requestFocusInWindow after the component is visible.)

however, this may not give you the granularity you want in focus retention...

worst case, you can try writing an intelligent windowListener to save/restore focus on windowActivated etc

good luck!
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic