KeyboardFocusManager.getCurrentKeyboardFocusManager().addPropertyChangeListener("focusOwner", new PropertyChangeListener() {
Color FOCUS_COLOR = Color.CYAN;
Component last;
Color background = null;
public void propertyChange(PropertyChangeEvent evt) {
Component current = (Component)evt.getOldValue();
Component future = (Component)evt.getNewValue();
if(current==last && current != null) {
current.setBackground(background);
}
last = future;
if(last!=null) {
background = last.getBackground();
last.setBackground(FOCUS_COLOR);
}
}
});
....and voila! you get EVERY component that can ever get focus hightligted with your favorite color!
This is great for debugging focus traversal problems - and it actually also looks cool (at least if you find a better color ,)
If I also just could do this for the ToolTipManager then my gui-debugging would ROCK ;)
p.s. No patent is currently pending on similar code - at least none that i'm aware of (wink wink Ward ;)