Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6172529
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T23:24:38+00:00 2026-05-23T23:24:38+00:00

When changing tabs, JTabbedPane always focuses the first focusable Component inside the tab. How

  • 0

When changing tabs, JTabbedPane always focuses the first focusable Component inside the tab.
How can I change its behaviour so that it will either focus the last focused component or none at all?
Invoking requestFocus afterwards is not an option because JTabbedPane must not set the focus in the wrong field at all.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T23:24:38+00:00Added an answer on May 23, 2026 at 11:24 pm

    Take a look at: Remembering last focused component.

    You need to keep track of which component has focus in each tab. Then when a tab is selected, you need to change focus to the appropriate component. Here is the code taken from the link above:

    class TabbedPaneFocus extends JTabbedPane implements ChangeListener, PropertyChangeListener {
    
        private Hashtable tabFocus;
    
        public TabbedPaneFocus() {
            tabFocus = new Hashtable();
            addChangeListener(this);
            KeyboardFocusManager.getCurrentKeyboardFocusManager().addPropertyChangeListener(this);
        }
    
        /*
         * (non-Javadoc)
         * 
         * @see java.beans.PropertyChangeListener#propertyChange(java.beans.PropertyChangeEvent)
         */
        @Override
        public void propertyChange(PropertyChangeEvent e) {
            if ("permanentFocusOwner".equals(e.getPropertyName())) {
                final Object value = e.getNewValue();
                if (value != null) {
                    tabFocus.put(getTitleAt(getSelectedIndex()), value);
                }
            }
    
        }
    
        /*
         * (non-Javadoc)
         * 
         * @see javax.swing.event.ChangeListener#stateChanged(javax.swing.event.ChangeEvent)
         */
        @Override
        public void stateChanged(ChangeEvent e) {
            Object value = tabFocus.get(getTitleAt(getSelectedIndex()));
            if (value != null) {
                ((Component) value).requestFocusInWindow();
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

It is possible to make just some tabs focusable, for instance the first 3
i have a project with 3 tabs, first tab have tableview with navigation, i
Do you think changing directories inside bash or Perl scripts is acceptable? Or should
After changing the text in a tab control's tab header, how do I tell
UItableView style not changing. I have a tableView controller as one of the tabs
In my framework project I have a class that represents tabs in a content
I have Tab Control, with two tabs, and each tab contains a UserControl, the
I'm doing several things with the functions below in jQuery Tabs UI - changing
I have a tab widget created with 3 tabs in it. I need to
I'm using Visual c# express 2010, I have 3 tabs and on the first

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.