问题
I want to create a photo gallery in javafx using pop up window . But when I pass target image to a method to set content of a pop up window to that image primary image will be removed and pop up window will be open.Why?Please help me .Thank's ( Excuse my for my bad English!!! )
This is that snippet code .
final Popup popup = new Popup();
popup.getContent().add(image);
popup.setOnShown(new EventHandler<WindowEvent>(){
@Override
public void handle(WindowEvent t) {
image.setFitHeight(400);
image.setFitWidth(400);
}
});
popup.show(stage);
回答1:
Your image is an ImageView, which is a Node. No node can appear in two scenes, or twice in the same scene graph.
To fix this, create a new ImageView, using the same image displayed in the current image (Images may be reused, even though ImageViews may not).
final Popup popup = new Popup();
final ImageView popupImage = new ImageView(image.getImage());
popup.getContent().add(popupImage);
popup.setOnShown(new EventHandler<WindowEvent>(){
@Override
public void handle(WindowEvent t) {
popupImage.setFitHeight(400);
popupImage.setFitWidth(400);
}
});
popup.show(stage);
来源:https://stackoverflow.com/questions/22691243/pop-up-window-removes-primary-node-in-javafx