JavaFX ScrollPane showing objects outside of viewport
Asked Answered
H

1

0

In my current application I have created a ScrollPane with an AnchorPane as content. Depending on the actions of the user this AnchorPane will be filled with more or less images for which I use a Canvas(necessary for drawing more information on the image).

However when I scroll through the ScrollPane, all the child images are still being repainted even when they aren't inside the ViewPort. Has anyone else had this problem or a solution for this?

screenshot: https://dl.dropboxusercontent.com/u/51537629/images%20drawn%20outside%20of%20viewport.png

Initialization of the scrollpane:

iconPane = new AnchorPane();
iconPane.setStyle("-fx-background-color: white; -fx-border-color: gray;");
iconPane.setMinHeight(546);
iconPane.setMinWidth(814);
scrollpane = new ScrollPane();
scrollpane.setContent(iconPane);
scrollpane.setVisible(false);        
AnchorPane.setTopAnchor(scrollpane, 13.0);
AnchorPane.setBottomAnchor(scrollpane, 13.0);
AnchorPane.setLeftAnchor(scrollpane, 13.0);
AnchorPane.setRightAnchor(scrollpane, 13.0);

Creation of an icon:

private VBox createIconPane(TaskInformation tinfo) {
    VBox vbox = new VBox();
    Canvas canvas = new Canvas(75, 75);
    GraphicsContext gc = canvas.getGraphicsContext2D();
    Image im;
    if (tinfo.getCurrent() != null) {
        if (tinfo.isCurrentStop()) {
            String status = utilities.getCurrentTaskVersion(tinfo.getTask()).getStatus();
            if (status.equals("finished")) {
                im = new Image(this.getClass().getClassLoader().getResourceAsStream("dna-current.png"));
            } else if (status.equals("failed")) {
                im = new Image(this.getClass().getClassLoader().getResourceAsStream("dna-failed.png"));
            } else {
                im = new Image(this.getClass().getClassLoader().getResourceAsStream("dna-processing.png"));
            }
        } else {
            im = new Image(this.getClass().getClassLoader().getResourceAsStream("dna-current.png"));
        }
    } else {
        im = new Image(this.getClass().getClassLoader().getResourceAsStream("dna-excluded.png"));
    }
    gc.drawImage(im, 5, 5);
    gc.setStroke(Color.GREEN);
    gc.strokeText(tinfo.getFinished() + "", 59, 15);
    gc.setStroke(Color.RED);
    gc.strokeText(tinfo.getFailed() + "", 59, 28);
    gc.setStroke(Color.BLUE);
    gc.strokeText(tinfo.getProcessing() + "", 59, 41);
    Label namelabel = new Label(tinfo.getTask().getName());
    namelabel.setLayoutX(0);
    namelabel.setLayoutY(68);
    vbox.getChildren().addAll(canvas, 
    return vbox;
}

Addition of all icons to the view:

private void createChildIcon(TaskInformation tinfo) {
    VBox taskicon = createIconPane(tinfo);
    taskicon.setLayoutX((tinfo.getTask().getLevel() - 6) / 2 * 120 + 5);
    if (tinfo.getTask().getLevel() <= levelLastAddedTask && maxYCoor != 5) {
        maxYCoor += 95;
    }
    levelLastAddedTask = tinfo.getTask().getLevel();
    taskicon.setLayoutY(maxYCoor);
    iconPane.getChildren().add(taskicon);
    for (int count = 0; count < tinfo.getChildren().size(); count++) {
        createChildIcon(tinfo.getChildren().get(count));
    }
}

JDK: 7, but it can be compiled as older versions as well

JFX: 2.2.21

After some testing with one of my colleagues we discovered that it must be a Windows issue. It works perfectly on Linux, but not on Windows.

Hi answered 2/4, 2013 at 13:12 Comment(1)
Possibly, it is a bug. But I've never seen such one. Could you provide the next info: version of JDK, version of JFX (version, build, if you know) and could you provide a test case? - a piece of code, where I can try and see the issue. Thanks.Melan
C
1

Try adding VM option "-Dprism.order=j2d". This is a work-around rather than a solution because it is replacing your hardware accelerated graphic pipeline with a software pipeline. If this works, add VM option "-Dprism.verbose=true" so that we can see what hardware was problematic.

I added a bug in the JavaFX Issue Tracker: https://javafx-jira.kenai.com/browse/RT-31044.

Came answered 10/6, 2013 at 22:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.