Wednesday, July 03, 2013

Tracking focus in Java

After a lot of experimenting I found a reliable way to track which controls are getting focus:
Component currFocus = null;

KeyboardFocusManager.getCurrentKeyboardFocusManager().addPropertyChangeListener(
  new PropertyChangeListener(){
    public void propertyChange(PropertyChangeEvent e){
      String prop = e.getPropertyName();
      if ((prop.equals("focusOwner"))){
        if(e.getNewValue() != null){
          currFocus = (Component)e.getNewValue();
        }
      }
    }
  }
);

6 comments:

Richard C. Lambert said...

Very awesome!!! When I seek for this I found this website at the top of all blogs in search engine.
shop audemars piguet watches

UNKNOWN said...

Needed to compose you a very little word to thank you yet again regarding the nice suggestions you’ve contributed here.

Java Training in Bangalore

Anonymous said...

This is what I have been searching in many websites and I finally found it here. Amazing article. I am so impressed. Could never think of such a thing is possible with it...I think you have a great knowledge especially while dealings with such subjects. Set up Call Forwarding on your phone

Melinda Mullen said...

cz

Michael Hollifield said...

Hello, this is fastidious top web designer post I actually loved reading this.

Lauren Chevalier said...

Keep the balls rolling!! Nice posts you have given for us.
mobile app design and development company