按ID删除节点

时间:2016-12-09 12:18:53

标签: java

我创建的每个对象都有一个唯一的ID。创建并选择一些节点后,我将所选节点的ID存储在列表中。

我想通过我存储的唯一ID从另一个类中删除选定的节点。

为此,我尝试从父级(AnchorPane)中删除节点:

Controller.rightAnchor.getChildren().get(i).remove(customId); 

rightAnchor@FXML public AnchorPane rightAnchor;)是我的Controller类中的一个AnchorPane,customId是我班级中的public String customId;,我想执行一个命令。

customId = Node.selectList.get(i).getI();

我收到错误Cannot make a static reference to the non-static field Controller.rightAnchor,但我不知道原因。

还有其他方法可以通过ID删除我的节点吗?

我的完整课程:

public class CustomComponent implements Command{

    private ArrayList<Command> commandListNew = Node.commandList;
    private Node nde;
    private Command customCmd;
    public String customId;

    public void execute(){

        for(int i = 0; i < Node.selectList.size(); i++){        
            customId = Node.selectList.get(i).getI();
            //Get commands and store them to a arraylist
            customCmd = Node.selectList.get(i).getL();
            commandListNew.add(customCmd);

            Controller.rightAnchor.getChildren().get(i).remove(customId);           
        }
    }
}

修改

execute()内更改了我的代码,现在收到错误The method remove() is undefined for the type Node

for(int i = 0; i < Node.selectList.size(); i++){        
    customId = Node.selectList.get(i).getI();
    customCmd = Node.selectList.get(i).getL();
    commandListNew.add(customCmd);
    Controller vctr = new Controller();
    String nodeId;
    nodeId = vctr.rightAnchor.getChildren().get(i).getId();
    if(nodeId == customId){
        vctr.rightAnchor.getChildren().get(i).remove(/*What to add here?*/);
    }
}

我可以添加哪些remove()括号来删除我的Id所属的节点?

0 个答案:

没有答案