Reputation: 69
I have a TableView
with two Columns (let's call them A and B). I like to loop through column A and print their values to console. My code doesn't seem to work the way I want it to....
for (int i : myTable.getItems().size()) {
System.out.print(columnA.getCellData(i));
}
Suggestions?
Upvotes: 1
Views: 5755
Reputation: 575
I just checked the code and found a small correction - the type of the item for getCellData() must be String not object. For the first example, this would result in:
for (String[] o : myTable.getItems()) {
System.err.println(columnA.getCellData(o));
}
Upvotes: 0
Reputation: 1798
You almost had it! But I don't think that for
loop is valid - it expects an Array not an int.
for (Object o : myTable.getItems()) {
System.err.println(columnA.getCellData(o));
}
Or if you are using Java 8, this is a shorter way:
myTable.getItems().stream().forEach((o)
-> System.err.println(columnA.getCellData(o)));
This works for me. If it doesn't just comment and I'll see what's wrong.
Upvotes: 3