Jump to content

stop JTabbedPanel behaviour arrows

- - - - -

  • Please log in to reply
4 replies to this topic

#1
alix

alix

    Newbie

  • Members
  • PipPip
  • 28 posts
i want to stop jtabbedpanel from switching tabs when i press left or right
oracle.com java tutorial states that

Quote

To Switch to Specific Tabs

There are three ways to switch to specific tabs using GUI.
1. Using a mouse. To switch to a specific tab, the user clicks it with the mouse.
2. Using keyboard arrows. When the JTabbedPane object has the focus, the keyboard arrows can be used to switch from tab to tab.
3. bla bla bla
but it doesn't say anything on how to disable that behaviour because i have textfields in and if a user should accidentally types something and later wants to correct that he will try to press the left key but surprise! that switches tabs
my workaround to that was
panelForTabs.registerKeyboardAction(null, KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, 0), 0);

panelForTabs.registerKeyboardAction(null, KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, 0), 0); 
it works, but java informs me that registerKeyboardAction is now obsolete and i should use a combination of getActionMap and getInputMap for some reason
i'm pretty sure that there's an official way to get rid of the arrow behaviour, maybe someone knows better

#2
wim DC

wim DC

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,084 posts
  • Programming Language:Java, JavaScript, PL/SQL
  • Learning:Java
2 ways that i know work. But i can't explain why,i don't really understand it.


        tabPane.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, 0), 0);

        tabPane.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, 0), 0);


--------------------------------------------------------------------------------------------


        tabPane.setInputMap(JComponent.WHEN_FOCUSED, null);

        tabPane.setInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, null);

        tabPane.setInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW, null);



#3
alix

alix

    Newbie

  • Members
  • PipPip
  • 28 posts
thank you once more
shouldnt tabpane have a .noDefaultInputMap or something

#4
wim DC

wim DC

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,084 posts
  • Programming Language:Java, JavaScript, PL/SQL
  • Learning:Java
I was wondering about that too. The weird thing about that inputmap, and which is why i'm so confused about it. Is that i can't seem to be able to remove stuff out of it.
I mean, when i debug and put the inputmap in my watch so I can see what's inside it, i clearly see the left and right in there (at position 2 and 3 here, but it's a map, so in theory that can vary).

However tabPane.getInputMap().remove(....) Does not remove anything.
Okay maybe the keys aren't the same. But, this is the most confusing part, even tabPane.getInputMap().clear(); seems to have no effect on the behaviour of the left and right arrow keys.

#5
alix

alix

    Newbie

  • Members
  • PipPip
  • 28 posts
well, the improv is doing well, i suppose i'll use that if everything else fails
thanks for your time :)




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users