java - 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
解决方案
您可以扩展 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) {...}
您可以扩展文本区域,然后使用类似的弹出窗口。棘手的部分是找到文本区域的插入符号位置,获取正在编辑的单词,然后能够将弹出窗口中的完成插入到正确位置的文本区域中。
推荐阅读
- laravel - /public 在更新 .htaccess 文件后仍然出现在某些 URL 中,但没有出现在其他 URL 中
- c - 递归 realloc() 在第 7 个 cicle 之后抛出“无效的下一个大小”
- html - 将图像对齐在右侧
- sql - SQL - 根据月份和日期过滤值
- hadoop - 查找从 Oozie 协调器启动的工作流作业的堆栈跟踪
- sql - 为什么此 SQL 查询在查询设计器中有效,但在 VBA for Access 中无效?
- java - 如何制作一个无法实现的界面?
- python-3.x - 如何在不遇到 Cython 无效语法错误“await = None”的情况下安装 SerpentAI
- eclipse - 如何从“安装新软件...”创建带有更新站点的目录
- chm - Windowshelp 到 htmlhelp