@@ -339,26 +339,28 @@ private int addComponentsToTabbedPane(List<ComponentPlaceholder> activeComponent
339
339
}
340
340
341
341
private void setupFocusUpdateListeners (JTabbedPane tabbedPane ) {
342
- registerSpacebarActionToTransferFocusToTabbedComponent (tabbedPane );
342
+ registerActionToTransferFocusToTabbedComponent (tabbedPane );
343
343
tabbedPane .addMouseListener (new MouseAdapter () {
344
344
@ Override
345
345
public void mousePressed (MouseEvent e ) {
346
346
int index = tabbedPane .indexAtLocation (e .getX (), e .getY ());
347
- Component selectedComponent = tabbedPane .getComponentAt (index );
348
- focusComponent (selectedComponent );
347
+ if (index >= 0 ) {
348
+ Component selectedComponent = tabbedPane .getComponentAt (index );
349
+ focusComponent (selectedComponent );
350
+ }
349
351
}
350
352
});
351
353
}
352
354
353
355
/**
354
- * Registers a keybinding that binds VK_SPACE to an action that transfers focus the
355
- * component represented by the currently focussed tab of a JTabbedPane. This is so that
356
- * when using keyboard focus traversal and the JTabbedPane get focus such that using arrow
357
- * keys allows the user to switch tabs, pressing the spacebar will transfer control to the
358
- * currently focused tab.
359
- * @param tabbedPane the JTabbedPane to add this spacebar keybinding.
356
+ * Registers a keybinding that allows the user to press the space bar to transfer focus to the
357
+ * component inside of the current tab of the tabbed pane. When using keyboard navigation, the
358
+ * tabbed pane will place focus on its tabs, not on the components in the tabs. Adding the
359
+ * space bar trigger makes keyboard navigation easier by giving the user a method to focus the
360
+ * component represented by the tab.
361
+ * @param tabbedPane the JTabbedPane
360
362
*/
361
- private void registerSpacebarActionToTransferFocusToTabbedComponent (JTabbedPane tabbedPane ) {
363
+ private void registerActionToTransferFocusToTabbedComponent (JTabbedPane tabbedPane ) {
362
364
Action focusAction = new AbstractAction ("Focus" ) {
363
365
@ Override
364
366
public void actionPerformed (ActionEvent ev ) {
0 commit comments