0
votes

I'm trying to make a TextArea readonly, but the text I am setting the TextArea to is so long it needs to be scrolled. A scroll bar appears when the text is set, but the scrollbar is not functioning.

I am using an .fxml file to hold my TextArea with the following code:

<TextArea fx:id="consultantScheduleTextArea" editable="false" focusTraversable="false" prefHeight="454.0" prefWidth="597.0" visible="false" />

My understanding is this is making it so I can't focus on it (like tab to the container or click into it), its not editable (so I can't change the text by typing), and it starts invisible. I've tried setting focusTraversable to true with no change of behavior.

In my controller, I set the visibility to true when a button is clicked then get some string data from a db, format it a certain way, then do this to set the content of the TextArea.

myTextArea.appendText(myString);

The result is my TextArea is filled with the content I have in myString, scrollbar is auto-created because the string is actually a lot of lines (lets say 300 lines), but again I cannot scroll it.

Any help?

EDIT: I didn't mention, this TextArea is wrapped in a stackpane which is wrapped in a gridpane. I don't think these matter at all, but just in case. This hierarchy is because its part of a complete app I have and this is just one component on one of the GUIs.

3
I just recreated what you said you did and I have no problem. Make sure you are using the latest jdk. - Sedrick
I just tried it with a very long string. It took a while to load but once loaded the scroll bar worked. - Sedrick
Try this to make sure your gui is not locking. Just a wild guess. Platform.runLater(()->{consultantScheduleTextArea.appendText(text.toString());}); and use StringBuilder where you can. - Sedrick
I don't think the GUI is locking as I can click other elements right away and change the scene around. I am using string builder up until text.toString() in the .appendText() call. I'm on the latest JDK too, haha. - Thomas Hughes
They were just wild guesses. I couldn't recreate your problem. - Sedrick

3 Answers

3
votes

try to use this on your TextArea

myTextArea.setEditable(false);

this make your text area read only and will make the scrollbar enable

2
votes

Alright, so some how with it being inside a stack pane, the scroll was not working. Not sure why, but that happened.

Unwrapped from stack pane and it works fine.

0
votes

For anyone else having a similar problem. My TextArea was in a Pane as a first element of the childrens and the scrollbar in the textarea was not working, I had to move it to the last element and it worked fine.