質問

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?

役に立ちましたか?

解決

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.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top