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);
有帮助吗?

解决方案

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);
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top