This method creates a treetableview dynamically. The problem is when I scroll to see the whole table or expand/collapse a treeitem, the position of word "yes" which is at first on cells which have same row and column name, changes.
<pre lang="java">
private TreeTableView<String> drawTable() {
root.setExpanded(true);
Set<String> funcAllKeys = new HashSet<>(dc.getSortedfuncAll().keySet());
funcAllKeys.removeAll(dc.getCombiFunc().keySet());
for (List<String> value : dc.getCombiFunc().values()) {
funcAllKeys.removeAll(value);
}
for (String valueremained : funcAllKeys) {
ArrayList<String> tempNameId = new ArrayList<>();
tempNameId.add(dc.getSortedfuncAll().get(valueremained));
root.getChildren().add(new TreeItem<String>(tempNameId.get(0)));
}
treeTable.setRoot(root);
Arrays.stream(dc.getRootKeys()).forEach(
rootKey -> root.getChildren().add(
createTreeItem(dc.getCombiFunc(), rootKey)));
TreeTableColumn<String, String> firstColumn = new TreeTableColumn<>("");
treeTable.getColumns().add(firstColumn);
firstColumn.setPrefWidth(80);
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());
}
});
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);
label.setTooltip(new Tooltip(label.getText()));
col.setPrefWidth(45);
TreeMap<String, List<String>> temp = (TreeMap<String, List<String>>) dc
.getFuncTypeOrg().clone();
List<String> list = temp.firstEntry().getValue();
String key = temp.firstEntry().getKey();
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>>() {
private List<Double> result = new ArrayList<Double>();
private List<Double> weight = new ArrayList<>();
private double lastresult = new Double(0);
public void updateItem(ArrayList<String> item,
boolean empty) {
super.updateItem(item, empty);
for (List<String> entry : dc.getFuncTypeOrg()
.values()) {
if (entry.get(1).equals(
this.getTreeTableRow().getItem())
&& label.getText().equals(
entry.get(5))) {
setText("here");
}
}
}
};
};
});
treeTable.getColumns().add(col);
}
treeTable.setPrefWidth(1200);
treeTable.setPrefHeight(500);
treeTable.setShowRoot(false);
treeTable.setEditable(false);
treeTable.setTableMenuButtonVisible(true);
return treeTable;
}
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;
}
}