/* * Tab has changed. Focus on saved component for the given tab. * When there is no saved component, focus on the first component. */ public void stateChanged(ChangeEvent e) { Component key = tabbedPane.getComponentAt(tabbedPane.getSelectedIndex()); if (key == null) return; Component value = tabFocus.get(key); // First time selecting this tab or focus policy is RESET_FOCUS if (value == null) { key.transferFocus(); tabFocus.put(key, value); } else // Use the saved component for focusing { value.requestFocusInWindow(); } }