Basil Bourque
Basil Bourque

Reputation: 339382

Get collection of components in a layout in Vaadin 8

Is there a way to get a collection of all the components contained in a Layout in Vaadin 8?

I have a GridLayout with a bunch of TextField objects. I'd like to set all of them to have 100% width. Rather than hand-code each explicitly, I'd rather write a soft-coded loop that looks through all the widgets in the layout.

Upvotes: 2

Views: 417

Answers (1)

Tatu Lund
Tatu Lund

Reputation: 10643

All Layouts in Vaadin 8, that can host multiple components (like GridLayout) implement HasComponents Interface

https://vaadin.com/download/release/8.4/8.4.4/docs/api/com/vaadin/ui/HasComponents.html

The interface defines Iterator, which can be used to go thru the components in the layout. I think it fits perfectly your purpose.

Since Java 8 is supported, Iterable supports also forEach(..).

Upvotes: 4

Related Questions