Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

How do I remove a node?

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Rancher
Posts: 387
30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks! I figured out the first part myself but your additional comments are very helpful.
 
reply
    Bookmark Topic Watch Topic
  • New Topic