JavaFX Span Tableview按MapEntries合并单元格 [英] JavaFX Span Tableview Merge Cells by MapEntries
问题描述
您好我有以下地图:
Map<String,ArrayList>
我想要这样的TableView
I would like to have a TableView like this
|--------------|-----------|
|ArrayList e1 | String e |
|--------------| |
|ArrayList e2 | |
|--------------| |
|ArrayList e3 | |
|--------------|-----------|
|ArrayList x1 | String x |
|--------------| |
|ArrayList x2 | |
|--------------|-----------|
我已经尝试了几个CellValueFactory Callbacks,但我没有任何线索如何读出我的值,并跨越或合并这些单元格。
I already tried it with several CellValueFactory Callbacks, but i don't have any clue how to read out my values and, span or merge these cells.
祝你好运
推荐答案
<我通过为第一列创建一个CellValueFactory来解决它,我将ArrayList作为String抓取,所以:
I solved it by creating a CellValueFactory for the first column where I grabbed the ArrayList as String so:
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,然后格式化单元格。
This handles the values for the column entries. Now i thought about a further representation form and used a CellFactory for this, which afterward formats the cell.
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);
这将替换[和]字符并将stringedArrayList拆分为ObservableList使用,作为拆分分隔符。
This replaces the "[" and "]" chars and splits the "stringed" ArrayList into an ObservableList by using "," as a split delimeter.
ObservableList用于ListView,然后通过以下行添加到单元格中:
The ObservableList is used for a ListView which is then added to the cell via the line:
setGraphic(listView);
。
|------|-----------|
| e1 | String e |
| e2 | |
| e3 | |
|------|-----------|
| x1 | String x |
| x2 | |
|------|-----------|
有什么不清楚的地方? - >只是评论。
Anything unclear? -> just comment.
这篇关于JavaFX Span Tableview按MapEntries合并单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!