您好我有以下地图:
Map<String,ArrayList>
我想要像这样的TableView
|--------------|-----------|
|ArrayList e1 | String e |
|--------------| |
|ArrayList e2 | |
|--------------| |
|ArrayList e3 | |
|--------------|-----------|
|ArrayList x1 | String x |
|--------------| |
|ArrayList x2 | |
|--------------|-----------|
我已经尝试了几个CellValueFactory Callbacks,但我不知道如何读出我的值,并跨越或合并这些单元格。
祝你好运
答案 0 :(得分:4)
我通过为第一列创建CellValueFactory解决了这个问题,我将ArrayList作为String抓取,所以:
arrayListCol.setCellValueFactory(new Callback<TableColumn.CellDataFeatures<Map.Entry<PropertyDifference, DifferenceFileList>, String>, ObservableValue<String>>() {
@Override
public ObservableValue<String> call(TableColumn.CellDataFeatures<Map.Entry<PropertyDifference, DifferenceFileList>, String> p) {
return new SimpleStringProperty(Arrays.toString(p.getValue().getValue().getFileList().toArray()));
}
});
结果:
|--------------|-----------|
|[e1,e2,e3] | String e |
|--------------|-----------|
|[x1,x2] | String x |
|--------------|-----------|
这将处理列条目的值。现在我考虑了一个进一步的表示形式,并使用了一个CellFactory,然后格式化单元格。
Callback<TableColumn<Map.Entry<PropertyDifference, DifferenceFileList>, String>, TableCell<Map.Entry<PropertyDifference, DifferenceFileList>, String>> tableCellList = new Callback<TableColumn<Map.Entry<PropertyDifference, DifferenceFileList>, String>, TableCell<Map.Entry<PropertyDifference, DifferenceFileList>, String>>() {
@Override
public TableCell<Map.Entry<PropertyDifference, DifferenceFileList>, String> call(TableColumn<Map.Entry<PropertyDifference, DifferenceFileList>, String> param) {
return new TableCell<Map.Entry<PropertyDifference, DifferenceFileList>, String>() {
@Override
protected void updateItem(String item, boolean empty) {
if (item != null) {
item = item.replace("[", "") .replace("]", "");
ObservableList<String> items = FXCollections.observableArrayList(item.split(","));
final ListView<String> listView = new ListView<String>();
listView.setItems(items);
setGraphic(listView);
}
}
};
}
};
arrayListCol.setCellFactory(tableCellList);
这取代了&#34; [&#34;和&#34;]&#34; chars and split the&#34; stringed&#34;使用&#34;,#34;将ArrayList放入ObservableList中作为拆分分隔符。
ObservableList用于ListView,然后通过以下行添加到单元格中:
setGraphic(listView);
|------|-----------|
| e1 | String e |
| e2 | |
| e3 | |
|------|-----------|
| x1 | String x |
| x2 | |
|------|-----------|
有什么不清楚的吗? - &GT;只是评论。