jmspinto
jmspinto

Reputation: 21

Update JavaFX nodes in a treeview

I am starting me in javafx. And I have a problem. I have a treeview where the nodes are changed his position by external command but it just does not see the tree. I have to minimize the parent and re-expand to see the effect. Altem any suggestions for that treeview can be refreshed as a code.

Exempo the code:

public Boolean SobeNodo()
{
    TreeItem<TreeNodo> oNodoSel = this.getSelectionModel().getSelectedItem();

    if (oNodoSel != null)
    {
         TreeItem<TreeNodo> oNodoPai = oNodoSel.getParent();
          if (oNodoPai != null)
          {
             int nIndex = oNodoPai.getChildren().indexOf(oNodoSel);
             if (nIndex > 0)
             {
                oNodoPai.getChildren().removeAll(oNodoSel);

                oNodoPai.getChildren().add(nIndex - 1, oNodoSel);

                return true;
             }
           }
    }
    return false;
}

Sorry for my English and thanks for the time spent.

Upvotes: 2

Views: 5705

Answers (1)

Sergey Grinev
Sergey Grinev

Reputation: 34508

You encountered an issue in TreeView: http://javafx-jira.kenai.com/browse/RT-20090

For now you can use next workaround (it's actually just a 50ms delay for 2nd operation with tree):

if (nIndex > 0) {
    oNodoPai.getChildren().removeAll(oNodoSel);

      TimelineBuilder.create().keyFrames(
        new KeyFrame(Duration.millis(50), new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent t) {
                oNodoPai.getChildren().add(nIndex - 1, oNodoSel);
            }
        })).build().play(); 

    return true;
}

Upvotes: 3

Related Questions