How could I create a listview at the current caret position in codearea while typing as autocompletion in javafx? So far I locate the word that is currently being typed and I see if that word is contained in the array. This is the code I have so far. Thank you in advance!
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?
}
});
Using Sai's answer I created my own solution!