Skip to main content

JTabbedPane and focus issues

1 reply [Last post]
Joined: 2004-06-02

Maybe I'm just doing things a bit different than anyone else and I'm all wrong. Here's the deal: I have a focus traversal policy for each frame in my app. When I used a personally-created subclass of JTabbedPane it was trying to set focus on a component on a non-visible tab. So I fixed that problem by not allowing focus to go to non-visible tab panels.

Now I want, on a tab change, to set focus on the first focusable component of the new tab. But at the time I get a change event to hook this call the old tab is still visible and the second one isn't.

So my first fix, which prevents focus from going to components on non-visible tabs, is stopping me from setting focus to anything on the tab that is about to become visible.

Is there another event that I can hook into AFTER the tab change has actually taken place? Or am I taking a completely wrong approach and does anyone smarter than me have a suggestion on how they are accomplishing both the above goals?

Thanks in advance for your consideration!

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2003-06-13

The first fix points to a different problem; your focus traversal class should have never suggested the component on a different tab because each tab would have its own focus-traversal.
See the help pages for focus traversal to find out its a hierarchy which means that the panel that contains your JTabbed pane is the 'parent' of the traversal policies on each tab.

To set focus to the fist focusable component, use the focus policy of the target tab, and set it with a request focus, or (have not tried) just set focus to the tab (contents)