Ctrl-Delete in JTextField

How can I get JTextFields to allow Ctrl - Delete and Ctrl - Backspace when editing text?

In various other programs, these key combinations can delete a whole word at a time.

From what I can tell, the default behavior of JTextField allows the user to use Ctrl to jump through the whole word when using the left and right keys and to select the whole word when using SHIFT . However, uninstallation simply does not work.

+4
source share
2 answers

Swing uses key bindings to map actions to components. To find out the default mappings for this component, you can use Key Bindings . The article also contains a link to the Swing tutorial, which contains the section "How to Use Key Bindings".

To create your own action, you must extend the TextAction so that you have access to the text component. Then you will need to get the current carriage position. You can then use the Utilities class to start or end the current word, and then you can remove characters from the document.

+4
source

You need to define an action and place it on the composite action map. See this article for an introduction.

0
source

All Articles