首页 > 解决方案 > how to use autocomplete in TextArea in javafx

问题描述

javafx provides support of autocomplete for TextField i want to use that feature for textArea

String[] autosuggestions = {"test","testing","etc etc"};
    TextFields.bindAutoCompletion(inputTextField, autosuggestions);

please help how can i use that for TextArea something like this

String[] autosuggestions = {"test","testing","etc etc"};
        TextFields.bindAutoCompletion(inputTextArea, autosuggestions);

any workaround will be appreciated please help

标签: javajavafxtextareatextfield

解决方案


您可以扩展 TextArea 组件并自己滚动它;这个例子 ( https://gist.github.com/floralvikings/10290131 ) 使用 TextField 执行此操作,可以使用 TextArea 完成相同类型的过程以从字符串数组中进行选择。

在编辑时,您可以检查插入符号位置附近的单词是否是列表中的部分完成,然后只需使用示例使用的弹出窗口手动完成所有操作。

该示例实现了一个更改侦听器:

textProperty().addListener(new ChangeListener<String>()
{
@Override
public void changed(ObservableValue<? extends String> observableValue, String s, String s2) { ... } });

这隐藏/显示了一个弹出窗口private void populatePopup(List<String> searchResult) {...}

您可以扩展文本区域,然后使用类似的弹出窗口。棘手的部分是找到文本区域的插入符号位置,获取正在编辑的单词,然后能够将弹出窗口中的完成插入到正确位置的文本区域中。


推荐阅读