Tab key navigation in JavaFX TextArea

后端 未结 6 1448
暖寄归人
暖寄归人 2021-02-02 16:47

How do I make hitting the Tab Key in TextArea navigates to the next control ?

I could add a listener to cath de key pressed event, but how do I make te TextArea control

6条回答
  •  情话喂你
    2021-02-02 17:11

    I had the same issue and I like the traverse-methods that Tom uses. But I also want to insert a tab when ctrl+tab is pressed.

    The call

    behavior.callAction("InsertTab");
    

    doesn´t work with JavaFX8. A look in the TextAreaBehaviour class showed me that there now is a "TraverseOrInsertTab" action.

    But however, I think this kind of action calling is quite unstable across several java versions because it relies on a string that is passed.

    So instead of the callAction() method, I used

    textArea.replaceSelection("\t");
    

提交回复
热议问题