Say I have an HBox like this:
val texts = new HBox {
content = Seq(new TextArea, new TextArea)
}
Now I'd like to get TextArea
s' text values in a collection. How can I get to these TextArea
s? texts.content
is an ObservableList[javafx.scene.Node]
, not ObservableList[TextArea]
.
I've tried type casting like this:
texts.content.get(0).asInstanceOf[TextArea].getText
And gott the following exception: java.lang.ClassCastException: javafx.scene.control.TextArea cannot be cast to scalafx.scene.control.TextArea
You can type cast the elements while fetching them, for example:
TextArea txt1 = (TextArea)observableList.get(0);
TextArea txt2 = (TextArea)observableList.get(1);
Or, if you have multiple TextArea
for(Node node: observableList){
TextArea txt = (TextArea)node;
//Do something with the txtArea
}