UPDATE: This qustion moved to TableColumn should only show one specific value of a complex data type because it's more specific
I want to populate a table with a complex data type Person
containing name
, id
and a List<Person>
. At the moment I get a table with the correct name
, id
and a third column with the whole information of other Person
s but it should only show the name of the Persons
s.
Is there any way that my third column shows only the Person.getName()
values?
Keywords, solutions welcome! Thank you very much!
Edit: Code
Person.class
public class Person {
String id;
String name;
List<Person> friends;
public String getId() {...}
public String getName() {....}
public List<Person> getFriends {...}
}
TableView.class
public TableView<Person> createTable() {
TableColumn<Person, String> firstCol = new TableColumn<>("ID");
TableColumn<Person, String> secondCol = new TableColumn<>("Name");
TableColumn<Person, List<Person> thirdCol = new TableColumn<>("Friends");
PropertyValueFactory<Person, String> firstColFactory = new PropertyValueFactory<>(
"id");
PropertyValueFactory<Person, String> secondColFactory = new PropertyValueFactory<>(
"name");
PropertyValueFactory<Person, List<Person>> thirdColFactory = new PropertyValueFactory<>(
"friends");
firstCol.setCellValueFactory(firstColFactory);
secondCol.setCellValueFactory(secondColFactory);
thirdCol.setCellValueFactory(thirdColFactory);
myTableView.getColumns().addAll(firstCol, secondCol, thirdCol);
}
So if I fill the table id
and name
-colums contain the correct name and the third column (with List<Person>
) shows [Person [id1, John, ...]...]]
.
And now I want to ask if theres a possibility that the third column only displays the id
or name
without manipulating the data?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…