pop up window removes primary node in javafx

情到浓时终转凉″ 提交于 2019-12-12 02:12:33

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!