Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Component having focus before button is pressed  RSS feed

 
Willem Kunkels
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!