7

I have an application with a tabbed pane and different components in it. I have set a MenuItem as Action with an Accelerator:

private final Action focusDefaultCommandsAction = new AbstractAction()
{
    {
        putValue(NAME, "Fokusiere Kommandoliste");
        putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_F6, 0));
    }

    @Override
    public void actionPerformed(final ActionEvent e)
    {
        invokeShowCommandsList();
    }
};

I know there is one tab where the Accelearator for the F6 key doesn't work. the F7 key works.

Is there maybe a default accelerator on a Swing Element that has priority over my accelerator?

Jason Plank
  • 2,336
  • 5
  • 31
  • 40
Neifen
  • 2,546
  • 3
  • 19
  • 31

1 Answers1

10

You can look this up in BasicLookAndFeel.java (or similar class depending on the L&F you use), search on F6.

Looks like F6 is used by JSplitPane to toggle focus between the content and the dividers. To remove it you could use something like (not tested, I think removing the actual action is harder because it might be in a parent input map):

splitPane.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT)
  .put(KeyStroke.getKeyStroke(KeyEvent.VK_F6, 0), "none");
Walter Laan
  • 2,956
  • 17
  • 15
  • 1
    Is any one knows a place where to find all the accelerators used by Swing components. Could be usefull – Tony Chemit Mar 29 '17 at 20:53
  • 1
    Note that JSplitPane also use F8 accelerator. – Tony Chemit Dec 21 '17 at 21:35
  • I arrived here because, as it turns out, a JTextPane somewhere was breaking my Ctrl+T accelerator from menubar. The code to fix it in my exact case was: `textPane.getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke('T', CTRL_DOWN_MASK), "Nothing");` – Dennis Soemers Jul 01 '19 at 13:28