1

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:

ObservableList<Tab>

for (....){

tabPane.getTabs().add(i);

)
4
  • 2
    what is Tab? which list ?
    – sanbhat
    Jul 3, 2013 at 10:01
  • insufficient information, provide a more detailed view of your question.... Jul 3, 2013 at 10:02
  • Is this the JFace databinding ObservableList type, or something else?
    – Krumelur
    Jul 3, 2013 at 10:03
  • Like any Iterable object, just need to read few things about Java basics :)
    – sp00m
    Jul 3, 2013 at 10:04

5 Answers 5

7

Java 8 supports .forEach()

ObservableList<Tab> tabs = ...
tabs.forEach((tab) -> { 
    System.out.println("Stuff with "+tab);
});
4
ObservableList<Tab> obList;

for(Tab tab : obList) {
  tab.doWhateverYouWant(); // "tab" is the reference to current Tab in this loop.
}
2

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
}
1

You can use a ListIterator<Tab> like this:

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(Tab currentTab : list) {
    // use currentTab here
}
1

Most likely there will be a get method to expose the Tabs. For example:

ObservableList<Tab> list = ...;
for (Tab tab: list.get()) {
    // do something
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.