java 如何在 JavaFX 的 ObservableList<Tab> 中循环
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17445022/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to loop in ObservableList<Tab> for JavaFX
提问by user1285928
I am working in JavaFX and I have this ObservableList<Tab>
. Can you tell me how I can loop and get the content of a content of the list? maybe something like this:
我在 JavaFX 工作,我有这个ObservableList<Tab>
. 你能告诉我如何循环并获取列表内容的内容吗?也许是这样的:
ObservableList<Tab>
for (....){
tabPane.getTabs().add(i);
)
回答by inyourcorner
Java 8 supports .forEach()
Java 8 支持 .forEach()
ObservableList<Tab> tabs = ...
tabs.forEach((tab) -> {
System.out.println("Stuff with "+tab);
});
回答by blalasaadri
You can use a ListIterator<Tab>
like this:
你可以使用ListIterator<Tab>
这样的:
ObservableList<Tab> list = ...;
Tab currentTab;
for(ListIterator<Tab> iterator = list.listIterator(); iterator.hasNext(); currentTab = iterator.next()) {
// use currentTab here
}
or even an enhanced for loop:
甚至增强的 for 循环:
for(Tab currentTab : list) {
// use currentTab here
}
回答by André Stannek
Do you mean a for each loop in which you do something with every element that's in the list?
您的意思是在每个循环中对列表中的每个元素执行某些操作吗?
ObservableList<Tab> myList = ...;
for (Tab tabPane : myList){
// Do whatever you want to do with tabPane
}
回答by jan.zanda
ObservableList<Tab> obList;
for(Tab tab : obList) {
tab.doWhateverYouWant(); // "tab" is the reference to current Tab in this loop.
}
回答by JeffinWithYa
Most likely there will be a get method to expose the Tabs. For example:
很可能会有一个 get 方法来公开选项卡。例如:
ObservableList<Tab> list = ...;
for (Tab tab: list.get()) {
// do something
}