开发者

Vaadin: How to iterate over Tabs in a TabSheet?

In Vaadin, say I have to find a Tab in a TabSheet based on its na开发者_Python百科me.

How do I iterate over the Tabs in the Tabsheet to accomplish this?


You can iterate the tabs and find them by the tab caption in the following way:

Iterator<Component> i = tabs.getComponentIterator();
while (i.hasNext()) {
    Component c = (Component) i.next();
    Tab tab = tabs.getTab(c);
    if ("some_caption".equals(tab.getCaption())) {
         // found it
    }
}


http://vaadin.com/api/com/vaadin/ui/TabSheet.html#getComponentIterator()


In Vaadin 7.x getComponentIterator() is deprecated. So @eeq answer is obsoleted.

In new manner his solution might look like:

Iterator<Component> iterator = tabSheet.iterator();
while (iterator.hasNext()) {
    Component component = iterator.next();
    TabSheet.Tab tab = tabSheet.getTab(component);
    if ("some tab caption".equals(tab.getCaption())) {
        // Found it!!!
    }
}

But since TabSheet implements java.lang.Iterable<Component> it could also look like this:

for (Component component : tabSheet) {
    TabSheet.Tab tab = tabSheet.getTab(component);
    if ("some tab caption".equals(tab.getCaption())) {
        // Found it!!!
    }
}

Or even in Java 8 style:

tabSheet.iterator().forEachRemaining(component -> {
    if ("some".equals(tabSheet.getTab(component).getCaption())) {
        // got it!!!
    }
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜