Vasting
Vasting

Reputation: 289

NextChild Function in JavaFX?

I have three TextArea that are all children of an HBox and I have selected one of them. I was wondering if there was a function for selecting the next child.

I tried to use a for loop of the parent node but I couldn't find a way to select a specific TextArea that was the next child of the one I already selected.

Upvotes: 0

Views: 31

Answers (1)

James_D
James_D

Reputation: 209330

// if you don't already have the index of the text field in its parent do:
int index = textField.getParent().getChildrenUnmodifiable().indexOf(textField);

// then
Node next = textField.getParent().getChildrenUnmodifiable().get(index+1);

Note though that in any typical setup, you won't really need these, as you would only have access to the text field within the same scope that you essentially added them to the parent. So you would "know" which text field followed which.

Upvotes: 1

Related Questions