在 javafx 中键入自动完成时,如何在 codearea 中的当前插入符号位置创建一个列表视图?到目前为止,我找到了当前正在输入的单词,并查看该单词是否包含在数组中。这是我到目前为止的代码。先感谢您!
String[] keyphrases = new String[]{"int main(){\n}", "cout", "cin"};
((CodeArea)tabPane.getSelectionModel().getSelectedItem().getContent()).textProperty().addListener(new ChangeListener<String>()
{
@Override
public void changed(ObservableValue<? extends String> observableValue, String s, String s2) {
CodeArea sto = ((CodeArea)tabPane.getSelectionModel().getSelectedItem().getContent());
String curr = "";
String currFinal = "";
for (int i = sto.getAnchor(); i > 0; i--) {
if (sto.getText().charAt(i) == '\n' || sto.getText().charAt(i) == ' ') {
break;
}else {
curr += sto.getText().charAt(i);
}
}
for (int i = curr.length()-1; i >= 0; i--) {
currFinal += curr.charAt(i);
}
System.out.println(currFinal);
ArrayList<String> fil = new ArrayList<String>();
for (int i = 0; i < keyphrases.length; i++) {
if (keyphrases[i].contains(currFinal)) {
fil.add(keyphrases[i]);
}
}
//display fil as listview in caret position?
}
});