Programmatically edit TreeView/TreeItem

后端 未结 2 856
后悔当初
后悔当初 2020-12-21 09:54

Edit #2: Since it looks like a bug i already posted a bug report in the javaFx-jira. You have to have an account to have access to the issue. I will keep th

2条回答
  •  -上瘾入骨i
    2020-12-21 10:20

    TreeCells (that is their content and binding to the treeItem) are updated lazily in a layout pass, that is very "late" when the next pulse is fired. A Platform.runLater(..) or any hard-coded delay may happen before or after that pulse, that's (probably) why both seem to work or not spuriously.

    So another whacky hack is to manually force a re-layout on the tree after having added a new item and before programatically starting an edit:

    root.getChildren().add(newItem);
    tree.layout();
    tree.edit(newItem);
    

    Needless to say, that this shouldn't be necessary - the current behaviour is a severe bug and must be fixed at once (... meaning ... jdk 9)

提交回复
热议问题