切换到Java 10时出错

时间:2018-08-22 04:42:17

标签: java canvas javafx-8 java-10 splitpane

我制作了一个使用水平SplitPane的Javafx程序,该画布的一侧绘制了一些画布。调整SplitPane的大小时,画布随之调整。 一切正常,直到我切换到Java10。突然,Canvas端只能扩展,而不能减少。 有人知道为什么吗? (有效的Java版本是1.8.0_181)

package test;

import javafx.application.Application;
import javafx.geometry.Orientation;
import javafx.scene.Scene;
import javafx.scene.control.SplitPane;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;

public class Test extends Application {

private static Display display;

@Override
public void start(Stage primaryStage) {

    display = new Display();
    StackPane stackPaneDisplay = new StackPane();
    stackPaneDisplay.getChildren().add(display);
    stackPaneDisplay.setStyle("-fx-background-color: white");

    AnchorPane anchorPaneDisplay = new AnchorPane();
    anchorPaneDisplay.getChildren().add(stackPaneDisplay);
    AnchorPane.setBottomAnchor(stackPaneDisplay, Double.MIN_VALUE);
    AnchorPane.setTopAnchor(stackPaneDisplay, Double.MIN_VALUE);
    AnchorPane.setLeftAnchor(stackPaneDisplay, Double.MIN_VALUE);
    AnchorPane.setRightAnchor(stackPaneDisplay, Double.MIN_VALUE);

    display.widthProperty().bind(stackPaneDisplay.widthProperty());
    display.heightProperty().bind(stackPaneDisplay.heightProperty());

    StackPane stackPaneLeft = new StackPane();

    SplitPane splitPane = new SplitPane();
    splitPane.setOrientation(Orientation.HORIZONTAL);
    splitPane.getItems().addAll(stackPaneLeft, anchorPaneDisplay);

    BorderPane root = new BorderPane();
    root.setCenter(splitPane);

    Scene scene = new Scene(root);
    primaryStage.setMaximized(true);

    primaryStage.setScene(scene);
    primaryStage.show();

    splitPane.setDividerPositions(0.2);

}

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

}

和画布类

package test;

import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;

public class Display extends Canvas {

GraphicsContext gc = this.getGraphicsContext2D();

public Display() {
    widthProperty().addListener(e -> {
        draw();
    });
}

public void draw() {
    gc.strokeOval(500, 500, 100, 100);
}

}

预先感谢

1 个答案:

答案 0 :(得分:0)

好的,我在stackoverflow上找到了解决方法

https://stackoverflow.com/a/34264033/4892909

它被user458577回答

对他表示敬意