Jaxafx选择框onKeypressed项目列表消失

时间:2018-12-25 05:04:09

标签: javafx

我是javafx的新手。我希望每当我按选择框上的键时,它都应专注于以键入的字符开头的项目,而不将匹配的项目设置为选择框。我找到了代码

static String jumpTo(String keyPressed, String currentlySelected, List<String> items) {
    String key = keyPressed.toUpperCase();
    if (key.matches("^[A-Z]$")) {
        // Only act on letters so that navigating with cursor keys does not
        // try to jump somewhere.
        boolean letterFound = false;
        boolean foundCurrent = currentlySelected == null;
        for (String s : items) {
            if (s.toUpperCase().startsWith(key)) {
                letterFound = true;
                if (foundCurrent) {
                    return s;
                }
                foundCurrent = s.equals(currentlySelected);
            }
        }
        if (letterFound) {
            return jumpTo(keyPressed, null, items);
        }
    }
    return null;
}

但是它关闭了附件列表,并将匹配项设置为选择框。我知道上面的函数肯定会从列表中返回匹配的字符串。但是我没有得到在上面的功能上做些什么修改,以便我得到想要的结果。

先谢谢了。

0 个答案:

没有答案
相关问题