Keyboard Focus question

Here’s a question for anybody!

In my app, I have a configuration panel that configures whichever object the user has selected. Each time the “current” object changes, a configuration view becomes visible for that object, while the previously selected object’s view becomes invisible. Now, as the user scrolls through to edit different objects, I want my keyboard focus to stay in the same part of the new view as it was for the previous object. However, as soon as the old view becomes invisible, focus jumps to the next visible component in the focus traversal.

If I record which component has focus before it comes invisible, and then ask its newly visible counterpart to grab focus, I’ll get an undesirable flicker, as the next component that wanted focus already got it before I called grabKeyboardFocus on the new guy.

Does anybody have any ideas?