通过JList中的字母停用选择 [英] Deactivate selection by letter in JList

查看:74
本文介绍了通过JList中的字母停用选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个JList列表和以下代码行:

I've got a JList list and the following code line:

list.getInputMap().put(KeyStroke.getKeyStroke('d'), "action");

因此,当我的列表成为焦点时,我按键盘上的 d 键,应执行一项操作.该操作考虑了当前选择了我的JList的哪个项目.问题在于,只要列表中有第一个字母为"d"的项目,我的选择就会首先跳至该条目,然后执行操作(应用于错误的项目).

So when my list is in focus and I press the d key on my keyboard an action should be performed. That action takes into account which item of my JList is currently selected. The problem is that whenever there is an item in my list with first letter 'd' my selection will jump to that entry first and then do the action (applied to the wrong item).

所以我的问题是:如何禁用由键入字母引起的JLists中的那些选择跳转?

So my question is: How do I disable those selections jumps in JLists caused by typing a letter?

推荐答案

您可以删除

You can remove the KeyListeners from the JList.
I tried but couldn't figure out what this breaks in terms of standard functionality.

KeyListener[] lsnrs = list.getKeyListeners();
for (int i = 0; i < lsnrs.length; i++) {
    list.removeKeyListener(lsnrs[i]);
}

这篇关于通过JList中的字母停用选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆