O JavaFX TreeView está vazio
Eu sou novo em trabalhar comJavaFX
e estou tentando criar umTreeView
para adicionar a umTab
. Quando adiciono oTreeView
aoTab
, no entanto, está vazio. Abaixo está o código que cria, preenche e adiciona oTreeView
aoTab
.
public ResultView(List<WebPage> results, int resultNum) {
this.pagesWithResults = results;
urls = new ArrayList<String>();
outputs = new ArrayList<>();
resultsTab = new Tab("Result" + resultNum);
resultTree = new TreeView<>();
branches = new ArrayList<>();
for(WebPage pageWithResults: pagesWithResults) {
this.urls.add(pageWithResults.getURL());
this.outputs.add(pageWithResults.getOutput());
}
TreeItem<String> root = new TreeItem<>();
root.setExpanded(true);
//resultTree.setShowRoot(false);
for(int i = 0; i < urls.size(); i++) {
branches.add(makeBranch(urls.get(i), root));
//System.out.println(urls.get(i));
for(int j = 0; j < outputs.get(i).size(); j++) {
makeBranch(outputs.get(i).get(j), branches.get(i));
//System.out.println(outputs.get(i).get(j));
}
}
resultsTab.setContent(resultTree);
}
public TreeItem<String> makeBranch(String title, TreeItem<String> parent) {
TreeItem<String> item = new TreeItem<>(title);
item.setExpanded(true);
parent.getChildren().add(item);
return item;
}
oTreeItems
são criados nomakeBranch
e adicionado ao método fornecidoparent
.
Aqui está o que oTab
parece que quando adicionado a umScene
: