File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How do I remove a node?

 
Rick Roman
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
FX newbie question: Say I have a scene that contains a group that contains a bunch of imageview nodes. Like a game board with a bunch of pieces on it. How do I remove one of the pieces (nodes) and have this reflected on the screen? If I could get an answer in regular java codse style, that would be great.
 
Darryl Burke
Bartender
Posts: 5115
11
Java Netbeans IDE Opera
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Rick and welcome to the Ranch!

How did you add the Nodes to the Group? There's a corresponding method for removing them.

To get better help sooner, post a SSCCE (Short, Self Contained, Compilable and Executable) example that demonstrates the problem. Not all your code; just what's relevant to any specific problem.
 
Rick Roman
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Group boardGroup = new Group();
ImageView stone1 = new ImageView(stone_image, x, y);
ImageView stone2 = new ImageView(stone_image, x, y);
ImageView stone3 = new ImageView(stone_image, x, y);
boardGroup.getChildren().add(stone1);
boardGroup.getChildren().add(stone2);
boardGroup.getChildren().add(stone3);
-- or --
boardGroup.getChildren().add(new ImageView(stone_image, x,y));
Scene scene = new Scene(boardGroup, 400, 400);
stage.setScene(scene);
stage.show();

Now the stones are on the screen. How do I remove them? I figured out how to do that by making them not visible but I would like to be able to actually remove the ImageView nodes. I've extended ImageView so I can find the node I want to delete but I don't know how to get rid of it.
 
John Damien Smith
Ranch Hand
Posts: 236
12
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Now the stones are on the screen. How do I remove them?


I've extended ImageView so I can find the node I want to delete

Although you may have other reasons to extend ImageView, you don't need to extend ImageView just to do that.
You can use list operations on boardGroup.getChildren() to get nodes by index or object reference or assign a css id to nodes and use the node.lookup(id) function on the group or scene to lookup the node by id.
 
Rick Roman
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks! I figured out the first part myself but your additional comments are very helpful.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic