• 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

Component having focus before button is pressed

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

I have a JButton on a JDialog (and a lot of other components too) that can minimize that dialog to the System Tray.

When the JDialog is made visible again from the System Tray, I want to set the focus back to the component on the JDialog that had the focus before the 'minimize to tray' JButton was pressed (which may be any of the components on that dialog).

Is their a handy way of doing this? I looked through the Swing API for a suitable method but I did not find anything. I guess I could implement the focus lost event for every single component on the JDialog, but that seems a bit of an overkill. For now, I just set the focus to a specific component, but I want to make the dialog a bit more user friendly.

Any help would be appreciated, thanks,

Willem.

I may have answered my on question. I checked the FocusEvent class, which has a method getOppositeComponent() which seems to do what I need.

Cheers,

Willem.
 
Any sufficiently advanced technology will be used as a cat toy. And this tiny ad contains a very small cat:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic