2016-09-14 48 views
1

如何使用scrollPane在全屏應用程序中顯示大於屏幕的圖像?我有一個大約爲8000x3800像素的圖像,我希望能夠移動整個圖像並與其進行交互,而無需調整大小。如果你希望關於我的代碼的細節,或者一般問問。如何使用scrollPane顯示大於屏幕的圖像JavaFX

public class SourceCodeVersion8 extends Application{ 

    public static void main(String[] args) { 
     launch(args); 
    } 

    @Override 
    public void start(Stage primaryStage) throws Exception { 
     AnchorPane mapAnchorO = addMapAnchor(); 
     Scene mapScene = new Scene(mapAnchorO); 
     primaryStage.setScene(mapScene); 
     primaryStage.setFullScreen(true); 
     primaryStage.setResizable(false); 
     primaryStage.show(); 
    } 

    //Creates an AnchorPane for the map 
    private AnchorPane addMapAnchor() 
    { 
     AnchorPane mapAnchor = new AnchorPane(); 
     ScrollPane mapScrollO = addMapScroll(); 
     mapAnchor.getChildren().add(mapScrollO); 
     AnchorPane.setLeftAnchor(mapScrollO, 0.0); 
     AnchorPane.setTopAnchor(mapScrollO, 0.0); 
     return mapAnchor; 
    } 

    //Creates an ImageView for the map 
    private ImageView addMapView() 
    { 
     Image mapImage = new Image("WorldProvincialMap-v1.01.png"); 
     ImageView mapView = new ImageView(mapImage); 
     return mapView; 
    } 

    //Creates a scrollPane for the map 
    private ScrollPane addMapScroll() 
    { 
     ScrollPane mapScroll = new ScrollPane(); 
     ImageView mapViewO = addMapView(); 
     mapScroll.setContent(mapViewO); 
     mapScroll.setPannable(true); 
     return mapScroll; 
    } 

} 
+0

我有但它不允許平移,即使我啓用該選項。另外,即使啓用該選項,它也不會顯示滾動條。 –

+0

編輯的問題包括我的代碼。 –

回答

3

只設置了4個錨2的ScrollPane,這就是爲什麼ScrollPane永遠不會調整,只是重新調整到允許顯示整個圖像的尺寸。

因此沒有必要的滾動條和不能完成平移。

你可以通過設置右側和底部錨點來解決這個問題。或者直接使用ScrollPane作爲Scene的根。

private AnchorPane addMapAnchor() { 
    AnchorPane mapAnchor = new AnchorPane(); 
    ScrollPane mapScrollO = addMapScroll(); 
    mapAnchor.getChildren().add(mapScrollO); 
    AnchorPane.setLeftAnchor(mapScrollO, 0.0); 
    AnchorPane.setTopAnchor(mapScrollO, 0.0); 
    AnchorPane.setBottomAnchor(mapScrollO, 0.0); 
    AnchorPane.setRightAnchor(mapScrollO, 0.0); 
    return mapAnchor; 
} 
相關問題