Question

Java tuturial says that "To make a component ignore a key that it normally responds to, you can use the special action name "none". For example, the following code makes a component ignore the F2 key:

component.getInputMap().put(KeyStroke.getKeyStroke("F2"), "none");

"

And there is a method getInputMap().remove(KeyStroke.getKeyStroke("F2"));

What is the difference? Why to use the first method?

Was it helpful?

Solution

To expand a little on VGR's comment, using "none" will only affect a single component. Using remove() on the components InputMap will also only affect that component.

You could also remove the binding from the LAF InputMap:

component.getInputMap().getParent().remove(...);

In this case the binding is removed for all components of that class. This will affect any component that has been created or will be created in your application.

you can use the special action name "none".

Also, "none" is not a special name. It is just a value that is used when a lookup is done on the ActionMap. If no Action is found using this value then nothing happens.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top