弹出窗口删除javafx中的主节点 [英] pop up window removes primary node in javafx
问题描述
我想使用弹出窗口在javafx中创建照片库。
但是当我将目标图像传递给方法以将弹出窗口的内容设置为该图像时,主图像将被删除并弹出窗口将打开。为什么?请帮助我。谢谢
(借口)我的英语不好!!!)
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!!! )
这是代码片段。
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);
推荐答案
您的图像是一个ImageView,它是一个节点。没有节点可以出现在两个场景中,或者在同一场景图中出现两次。
Your image is an ImageView, which is a Node. No node can appear in two scenes, or twice in the same scene graph.
要解决此问题,请使用当前图像中显示的相同图像创建新的ImageView(图像可以重复使用,即使ImageViews可能没有。)
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);
这篇关于弹出窗口删除javafx中的主节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!