I am making my own text editor in JavaFX and I want to have bracket completion. Like in Netbuns. I have tried using a ChangeListener on the TextArea and checking if the last character is a bracket and append the char like this:
textArea.textProperty().addListener(new ChangeListener<String>()
{
@Override
public void changed(final ObservableValue<? extends String> observable, final String oldValue, final String newValue)
{
if (textArea.getText().charAt(textArea.getText().length()-1) == '{')
{
textArea.appendText("}");
}
}
});
But since it's only checking the last character in the textArea, this doesn't work for code where there are brackets inside brackets. Does anyone know a way to fix this? It may also be helpful to note that I am using JDK 1.7.0_55 and my school refuses to update to JDK 8. Any help will be appreciated.
Aucun commentaire:
Enregistrer un commentaire