gpt4 book ai didi

java - 为什么鼠标事件后图像从标题 Pane 中消失?

转载 作者:行者123 更新时间:2023-12-01 10:40:47 25 4
gpt4 key购买 nike

我有一个带标题的 Pane ,我正在该 Pane 中显示图像,但该图像非常大,因此我调整它的大小以适合该 Pane 。由于图像变小,用户可能希望以原始尺寸查看它,因此我实现了一种通过鼠标单击在新的更大窗口中打开原始图像的方法。

    imgViewPicture.setFitWidth(titledPanePicture.getPrefWidth());
imgViewPicture.setPreserveRatio(true);
imgViewPicture.setSmooth(true);
imgViewPicture.setCache(true);
titledPanePicture.setContent(imgViewPicture);

问题是,当我单击 titledPanePicture 时,小图像消失,其内容被清除。为什么?对于解决方案,我添加了在鼠标单击事件上重新加载内容。但我不喜欢它,我认为 titledPanePicture 的内容应该保持不变。

这是我的鼠标单击事件:

    Stage stage = new Stage();
stage.initModality(Modality.APPLICATION_MODAL);
Group root = new Group();
Scene scene = new Scene(root);
scene.setFill(Color.BLACK);
HBox box = new HBox();
imgViewPicture.setFitWidth(0);
box.getChildren().add(imgViewPicture);
root.getChildren().add(box); // before tPane

stage.setTitle("Picture Original Size");
stage.setScene(scene);
stage.sizeToScene();
stage.show();
reloadContentofTitledPane(); // This line is the fix but I find it unnecessary

建议,我们将不胜感激。

最佳答案

您似乎在两个场景中使用相同的ImageView。但是,节点只能放置在单个场景图中的单个位置。

为新场景创建一个新节点。

ImageView newImageView = new ImageView(imgViewPicture.getImage());
...
box.getChildren().add(newImageView);

关于java - 为什么鼠标事件后图像从标题 Pane 中消失?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34416079/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com