File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes JTabbedPane - traversing focus through tabs Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JTabbedPane - traversing focus through tabs " Watch "JTabbedPane - traversing focus through tabs " New topic

JTabbedPane - traversing focus through tabs

Juan Antonio Ramirez

Joined: Sep 18, 2007
Posts: 2
I would like to have focus traverse through tabs in a JTabbedPane. That is, when the focus is on the last component of a tab, hitting the key for forward focus traverse should bring up the next tab and focus on the first component on that tab. I'm already using a custom FocusTraversalPolicy on the panel containing the JTabbedPane, which handles focus traversal between the components on the tabs. This policy has no knowledge of which tab a particular component is on.

I was hoping calling requestFocusInWindow() would automagically focus that tab, but it doesn't. Needless to say, having the focus traversal policy cycle through all the components (including those in non-selected tabs) doesn't work, either. Is there an elegant way to do this, without resorting to listening to key events, watching for the TAB key, and switching to the appropriate tab?
Krithika Srinath
Ranch Hand

Joined: Apr 11, 2006
Posts: 52
Which version of JDK and Windows you are using? There is bug with JDK 1.4.1 with XP on traversing in JTabbedPane. Check this out. Not sure you are hitting this bug.
All The Best.
Juan Antonio Ramirez

Joined: Sep 18, 2007
Posts: 2
Sorry, JDK 1.6, Windows XP.

The issue is not Ctrl+Tab not working, but rather an extension to the normal Tab keyboard focus system, where I want focus traversing into the next tab in a JTabbedPane after the last component in a particular tab. Call it an implicit Ctrl+Tab when hitting Tab when the last component in a tab is focused.
I agree. Here's the link:
subject: JTabbedPane - traversing focus through tabs
It's not a secret anymore!