0

在我当前的应用程序中,我创建了一个以 AnchorPane 作为内容的 ScrollPane。根据用户的操作,此 AnchorPane 将填充或多或少的图像,我使用 Canvas(在图像上绘制更多信息所必需)。

但是,当我滚动 ScrollPane 时,所有子图像仍在重新绘制,即使它们不在 ViewPort 内。有没有其他人遇到过这个问题或解决方案?

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

滚动窗格的初始化:

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);

创建图标:

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;
}

将所有图标添加到视图中:

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,但也可以编译为旧版本

JFX:2.2.21

在与我的一位同事进行一些测试后,我们发现这一定是 Windows 问题。它可以在 Linux 上完美运行,但不能在 Windows 上运行。

4

1 回答 1

1

尝试添加 VM 选项“-Dprism.order=j2d”。这是一种变通方法而不是解决方案,因为它正在用软件管道替换您的硬件加速图形管道。如果这可行,请添加 VM 选项“-Dprism.verbose=true”,以便我们可以查看哪些硬件存在问题。

我在 JavaFX 问题跟踪器中添加了一个错误:https ://javafx-jira.kenai.com/browse/RT-31044 。

于 2013-06-10T22:56:48.090 回答