1

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?

Lukas Betz
  • 126
  • 8
  • Try setMouseTransparent(true).If true, this node (together with all its children) is completely transparent to mouse events. – Oleks Jun 17 '19 at 09:38
  • Or check this answer https://stackoverflow.com/a/25630584/2244676 – Oleks Jun 17 '19 at 09:39
  • Problem with setMouseTransparent(true) is, that then scrolling is not possible aswell. The other answer helps me understand why my solution does not work. – Lukas Betz Jun 17 '19 at 10:16

1 Answers1

1

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.

Oleks
  • 1,011
  • 1
  • 14
  • 25
  • Thanks for the answer. For some reason I get a Nullpointerexception even when I run this code as last statement. But it worked now if i wait in a seperate thread until the scene is initialized. And after this I have to wait again until textArea.getScene().lookup("#idTextArea .content") is not null. Probably I should learn about the timing in JavaFX. – Lukas Betz Jun 18 '19 at 07:16
  • Lookup is not guaranteed to work until CSS has been applied to the scene so you need to invoke the code after WindowEvent.WINDOW_SHOWN event is generating. https://stackoverflow.com/a/16921731/2244676 In your case I guess the more reliable solution is editing external CSS file. – Oleks Jun 18 '19 at 08:27
  • None of the options worked for me. The Cursor only shows up in textArea borders, but not in content area. – lubrum Mar 11 '22 at 16:15