簡體   English   中英

為什么鼠標事件后圖像從標題窗格中消失了?

[英]Why image disappears from titled pane after mouse event?

我有一個標題窗格,並且正在此窗格中顯示圖像,但是該圖像很大,因此我調整了大小以適合該窗格。 由於圖像變小,用戶可能希望以原始大小查看它,因此我實現了一種方法,即通過鼠標單擊在更大的新窗口中打開原始圖像。

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

問題是,當我單擊titledPanePicture ,小圖像消失了,其內容被清除了。 為什么? 對於解決方案,我在mouseclick事件上添加了內容的重新加載。 但是我不喜歡它,我認為titledPanePicture的內容應該保持不變。

這是我的mouseclick事件:

    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 但是, Node只能放置在單個場景圖中的單個位置。

為您的新Scene創建一個新節點。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM