Search code examples
javajavafxcursortextarea

JavaFX: Change cursor in Textarea


I have a Textarea which I use to output status logs. I dont want the user to be able to put text in it, so i set editable to false. I also want the cursor to be the normal arrow-cursor, but that doesnt work.

I tried to set the cursor of the textarea but this did not work.

textArea.setCursor(Cursor.DEFAULT);

It still shows the usual text area cursor when hovering the text area and not the standard arrow cursor. What am I missing?


Solution

  • The reason why the solution doesn't work is answered here. If CSS is not the option for you try this approach:

    textArea.setId("idTextArea");// you can set also control id in fxml file
    textArea.getScene().lookup("#idTextArea .content").setCursor(Cursor.DEFAULT);
    

    Make sure that Scene object is initialized before running the code.