I have a ScrollPane which allows for wrapping around the screen through some nice code. However, in order to achieve this I have had to use 5 ImageViews with each of them being the size of the screen. This causes the computer to run very slowly when panning around and loading. Is there a way to distribute the weight on the system or optimize the code so that it runs faster? I have a 1 year old computer that has a i7 processor so I know that this is not the issue and that it is the code. Anyways here is the code I have.package gameaspects;    import java.awt.GraphicsDevice;    import java.awt.GraphicsEnvironment;    import java.io.IOException;    import javafx.application.Application;    import javafx.beans.property.IntegerProperty;    import javafx.beans.property.SimpleIntegerProperty;    import javafx.concurrent.Task;    import javafx.geometry.Bounds;    import javafx.geometry.Insets;    import javafx.scene.Group;    import javafx.scene.Scene;    import javafx.scene.control.Button;    import javafx.scene.control.ScrollPane;    import javafx.scene.control.ScrollPane.ScrollBarPolicy;    import javafx.scene.image.Image;    import javafx.scene.image.ImageView;    import javafx.scene.input.KeyCode;    import javafx.scene.input.KeyCombination;    import javafx.scene.input.MouseEvent;    import javafx.scene.input.ScrollEvent;    import javafx.scene.layout.AnchorPane;    import javafx.scene.layout.GridPane;    import javafx.scene.layout.VBox;    import javafx.stage.Popup;    import javafx.stage.Stage;    public class SourceCodeVersion8 extends Application{final double SCALE_DELTA = 1.1;public double SCALE_TOTAL = 1;public static int game_speed = 5, day = 1, month = 1, year = -813, pause = 0;public IntegerProperty dayProperty, monthProperty, yearProperty, pauseProperty, game_speedProperty;public int dragDetected = 0;//0 is no drag detectedstatic GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();static SourceCodeVersion8 sourceObject = new SourceCodeVersion8();public static void main(String[] args) {    new Thread(task).start();    launch(args);}@Overridepublic void start(Stage primaryStage) throws Exception {    Popup exitPopupO = addExitPopup();    AnchorPane mapAnchorO = addMapAnchor();    Scene mapScene = new Scene(mapAnchorO);    primaryStage.setScene(mapScene);    primaryStage.setFullScreen(true);    primaryStage.setResizable(false);    primaryStage.setFullScreenExitKeyCombination(KeyCombination.NO_MATCH);    primaryStage.show();    mapScene.setOnKeyPressed(e -> {        if(e.getCode()==KeyCode.ESCAPE)        {            exitPopupO.show(primaryStage);        }    });}//Creates an AnchorPane for the mapprivate 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;}//Creates an ImageView for the mapprivate ImageView addMapView(){    Image mapImage = new Image(WorldProvincialMap-v1.01.png);    ImageView mapView = new ImageView(mapImage);    //Sets the map to full screen.    int width = gd.getDisplayMode().getWidth();    int height = gd.getDisplayMode().getHeight();    mapView.setFitHeight(height);    mapView.setFitWidth(width);    return mapView;}//Creates a gridPane to hold the ImageViewprivate GridPane addMapGrid(){    GridPane mapGrid = new GridPane();    ImageView mapView1 = addMapView();    ImageView mapView2 = addMapView();    ImageView mapView3 = addMapView();    ImageView mapView4 = addMapView();    ImageView mapView5 = addMapView();    mapGrid.add(mapView1,0,0);    mapGrid.add(mapView2, 1, 0);    mapGrid.add(mapView3, 2, 0);    mapGrid.add(mapView4, 3, 0);    mapGrid.add(mapView5, 4, 0);    mapGrid.setManaged(false);    return mapGrid;}//Creates a scrollPane for the mapprivate ScrollPane addMapScroll(){               ScrollPane mapScroll = new ScrollPane();    GridPane mapGridO = addMapGrid();    mapScroll.setContent(new Group(mapGridO));    mapScroll.setPannable(true);    //Removes the ScrollBars    mapScroll.setVbarPolicy(ScrollBarPolicy.NEVER);    mapScroll.setHbarPolicy(ScrollBarPolicy.NEVER);    //Sets to the center image    mapScroll.setHvalue(0.5);    //Adds functionality to scrolling    mapScroll.addEventFilter(ScrollEvent.ANY, e ->{        //Consumes the event        e.consume();        if(e.getDeltaY() == 0)        {            return;        }        double scaleFactor =                  (e.getDeltaY() > 0)                    ? SCALE_DELTA                    : 1/SCALE_DELTA;        //Ensures that you do not exceed the limits of the map        if(scaleFactor * SCALE_TOTAL >= 1)        {            Bounds viewPort = mapScroll.getViewportBounds();            Bounds contentSize = mapGridO.getBoundsInParent();            double centerPosX = (contentSize.getWidth() - viewPort.getWidth()) * mapScroll.getHvalue() + viewPort.getWidth() / 2;            double centerPosY = (contentSize.getHeight() - viewPort.getHeight()) * mapScroll.getVvalue() + viewPort.getHeight() / 2;            mapGridO.setScaleX(mapGridO.getScaleX() * scaleFactor);            mapGridO.setScaleY(mapGridO.getScaleY() * scaleFactor);            SCALE_TOTAL *= scaleFactor;            double newCenterX = centerPosX * scaleFactor;            double newCenterY = centerPosY * scaleFactor;            mapScroll.setHvalue((newCenterX - viewPort.getWidth()/2) / (contentSize.getWidth() * scaleFactor - viewPort.getWidth()));            mapScroll.setVvalue((newCenterY - viewPort.getHeight()/2) / (contentSize.getHeight() * scaleFactor  -viewPort.getHeight()));        }    });    mapScroll.addEventFilter(MouseEvent.DRAG_DETECTED, e -> {        dragDetected = 1;    });    mapScroll.addEventFilter(MouseEvent.MOUSE_RELEASED, e -> {        if(dragDetected == 1)        {            if(mapScroll.getHvalue() <= 0.3)            {                mapScroll.setHvalue(mapScroll.getHvalue() + 0.4);            }            else if(0.3 < mapScroll.getHvalue() && mapScroll.getHvalue() <= 0.5)            {                mapScroll.setHvalue(mapScroll.getHvalue() + 0.2);            }            else if(0.7 < mapScroll.getHvalue() && mapScroll.getHvalue() <= 0.9)            {                mapScroll.setHvalue(mapScroll.getHvalue() - 0.2);            }            else if(0.9 <= mapScroll.getHvalue())            {                mapScroll.setHvalue(mapScroll.getHvalue() - 0.4);            }        }        dragDetected = 0;    });    return mapScroll;}private Popup addExitPopup(){    Popup exitPopup = new Popup();    //Exit Panel    VBox exitBox = new VBox();    exitBox.setPadding(new Insets(10));    Button exitPaneExit = new Button();    exitPaneExit.setText(Return);    exitPaneExit.setMinSize(75.0, 30.0);    exitPaneExit.setOnAction(e -> {        exitPopup.hide();    });    Button exitButton = new Button();    exitButton.setText(Exit);    exitButton.setMinSize(75.0, 30.0);    exitButton.setOnAction(e -> {        System.exit(0);    });    exitBox.getChildren().addAll(exitPaneExit,exitButton);    exitBox.setVisible(true);    exitPopup.setAutoHide(true);    exitPopup.getContent().add(exitBox);    return exitPopup;}static Task<Void> task = new Task<Void>() {    @Override public Void call() throws IOException {    long initialTime = System.currentTimeMillis(); //Finds the current time and links it with a variable    while(true)    {        if(pause==0)//Makes sure the game is not running while paused        {            if(System.currentTimeMillis() - initialTime >= 500 &&game_speed == 5)//Lowest game speed 10 seconds per day            {                day++;//Hey its tomorrow!                sourceObject.setDayProperty(day);                initialTime = System.currentTimeMillis();//Resets time                if(day == 32)                {                    switch(month)                    {                        case 1:                            month++;                            day = 1;                            sourceObject.setDayProperty(day);                            sourceObject.setMonthProperty(month);                            break;                        case 3:                            month++;                            day = 1;                            break;                        case 5:                            month++;                            day = 1;                            break;                        case 7:                            month++;                            day = 1;                            break;                        case 8:                            month++;                            day = 1;                            break;                        case 10:                            month++;                            day = 1;                            break;                        case 12:                            month = 1;                            day = 1;                            year++;                            break;                        default:                            break;                    }                }                else if(day == 31)                {                    switch(month)                    {                        case 4:                            month++;                            day = 1;                            break;                        case 6:                            month++;                            day = 1;                            break;                        case 9:                            month++;                            day = 1;                            break;                        case 11:                            month++;                            day = 1;                            break;                        default:                            break;                    }                }                else if(day == 29)                {                    switch(month)                    {                        case 2:                            month++;                            day = 1;                            break;                        default:                            break;                    }                }                System.out.println(month +   + day +   + year);            }        }    }        };};public final int getDayProperty(){    return dayProperty.get();}public final void setDayProperty(int day){    this.dayProperty.set(day);}public final IntegerProperty dayInitialProperty(){    if(dayProperty == null)    {        dayProperty = new SimpleIntegerProperty(1);    }    return dayProperty;}public final int getMonthProperty(){    return monthProperty.get();}public final void setMonthProperty(int month){    this.monthProperty.set(month);}public final IntegerProperty monthInitialProperty(){    if(monthProperty == null)    {        monthProperty = new SimpleIntegerProperty(1);    }    return monthProperty;}}
ScrollPane which allows for wrapping around the screen
java;performance;javafx