[英]How do I display a “single bar chart” in a TableColumn of a TableView (javaFX 8)?
[英]JavaFX: How do you display the contents of a String[] in a TableColumn?
我有電影課。 角色保存在String []中。 我使用SceneBuilder創建了一個GUI。 我像這樣設置每個TC的值:
tableDirector.setCellValueFactory(new PropertyValueFactory<>("Director"));
tableActors.setCellValueFactory(new PropertyValueFactory<>(("actors")));
這適用於所有非Collections的東西,但是我不能為所有想找出如何將String []中的多個String放入單個列中的事物而熱愛。 我想念什么嗎?
假設您未顯示的所有代碼都是正確的,則可以執行
tableActors.setCellFactory(tc -> new TableCell<Movie, String[]>() {
@Override
protected void updateItem(String[] actors, boolean empty) {
super.updateItem(actors, empty);
if (empty || actors == null) {
setText(null);
} else {
setText(String.join(", ", actors));
}
}
});
一個更復雜的單元工廠可能會產生一個在ListView
或類似選項中顯示角色的單元。
請注意, cellFactory
是您已經定義的cellValueFactory
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.