2016-09-14 42 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; 
} 
相关问题