This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes JavaFX and the fly likes How do I remove a node? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » JavaFX
Bookmark "How do I remove a node?" Watch "How do I remove a node?" New topic
Author

How do I remove a node?

Rick Roman
Greenhorn

Joined: May 14, 2012
Posts: 3
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

Joined: May 03, 2008
Posts: 4523
    
    5

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.

luck, db
There are no new questions, but there may be new answers.
Rick Roman
Greenhorn

Joined: May 14, 2012
Posts: 3
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

Joined: Jan 26, 2012
Posts: 130
    
    9
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

Joined: May 14, 2012
Posts: 3
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
 
subject: How do I remove a node?
 
Similar Threads
Remove duplicate nodes in DOM
Number of child in root node of JTree
Overall performance of ArrayList vs. HashSet
MultiDimensional array doesnt work
running .profile file