行の名前が列の名前と等しい場合、セルにテキストを設定するツリーテーブルがあります。正常に動作しますが、ツリーアイテムを折りたたんだり拡張したり、下にスクロールすると値がセルに変わります。どうすればこの問題を克服できますか? updateItem メソッドでセルにテキストを設定する必要がありますか?
private TreeTableView<String> drawTable() {
root.setExpanded(true);
// ////////////////treetable////////////////////////////
/**
* makes treeTable and set the nodes to it.
* */
treeTable.setRoot(root);
Arrays.stream(dc.getRootKeys()).forEach(
rootKey -> root.getChildren().add(
createTreeItem(dc.getCombiFunc(), rootKey)));
// ////////////////First column/////////////////////////
/**
* creates first column with no caption and sets treeview for that.
* */
TreeTableColumn<String, String> firstColumn = new TreeTableColumn<>("");
treeTable.getColumns().add(firstColumn);// Tree column
firstColumn.setEditable(false);
firstColumn.setSortable(false);
firstColumn
.setCellValueFactory(new Callback<CellDataFeatures<String, String>, ObservableValue<String>>() {
public ObservableValue<String> call(
CellDataFeatures<String, String> p) {
return new ReadOnlyStringWrapper(p.getValue()
.getValue());
}
});
// //////////////////Rest Columns////////////////////////
/**
* go through all organizations which have a function and make column
*/
for (Entry<String, String> ent : dc.getSortedAssignedOrg().entrySet()) {
TreeTableColumn<String, ArrayList<String>> col = new TreeTableColumn<>();
Label label = new Label(ent.getValue());
col.setGraphic(label);
col.setEditable(false);
col.setSortable(false);
// //////////////cellfactory/////////////////////////
col.setCellFactory(new Callback<TreeTableColumn<String, ArrayList<String>>, TreeTableCell<String, ArrayList<String>>>() {
@Override
public TreeTableCell<String, ArrayList<String>> call(
TreeTableColumn<String, ArrayList<String>> param) {
return new TreeTableCell<String, ArrayList<String>>() {
public void updateItem(ArrayList<String> item,
boolean empty) {
super.updateItem(item, empty);
if (this.getTreeTableRow().getItem().equals(
label.getText()) {
setText("yes");
}
}
}
};
};
});// end cell factory
treeTable.getColumns().add(col);
}
// end for col
treeTable.setPrefWidth(1200);
treeTable.setPrefHeight(500);
treeTable.setShowRoot(false);
treeTable.setEditable(false);
treeTable.setTableMenuButtonVisible(true);
return treeTable;
}
//makes the tree hierarchy///
private TreeItem<String> createTreeItem(TreeMap<String, List<String>> data,
String rootKey) {
TreeItem<String> item = new TreeItem<>();
item.setValue(rootKey);
item.setExpanded(true);
List<String> childData = data.get(rootKey);
if (childData != null) {
childData.stream().map(child -> createTreeItem(data, child))
.collect(Collectors.toCollection(item::getChildren));
}
String valueName = item.getValue();
item.setValue((dc.getSortedfuncAll().get(valueName)));
return item;
}
}