我正在处理JavaFX级别编辑器的GUI,希望能够将画布对象调整为新的拆分窗格尺寸。但似乎无论我尝试什么都失败了。这包括传递窗格对象并直接使用其宽度、使用窗口大小监听器以及将宽度和高度属性绑定到拆分窗格上。有任何想法吗?下面是调整尺寸前后的截图:
是否有人有任何想法?该类的代码相当复杂,但此处将包含调整大小的代码:
public Canvas canvas;
public String tabTitle;
public VBox layout;
public GraphicsContext g;
public Core core;
public CanvasTab(Core core, String tabTitle){
this.core = core;
this.canvas = new Canvas(core.scene.getWidth() - 70, core.scene.getHeight() - 70);
layout = VBoxBuilder.create().spacing(0).padding(new Insets(10, 10, 10, 10)).children(canvas).build();
this.g = canvas.getGraphicsContext2D();
g.setFill(Color.BLACK);
g.fillRect(0, 0, canvas.getWidth(), canvas.getHeight());
HBox.setHgrow(layout, Priority.ALWAYS);
this.setContent(layout);
this.setText(tabTitle);
canvas.widthProperty().bind(layout.widthProperty().subtract(20));
canvas.heightProperty().bind(layout.heightProperty().subtract(20));
}
public CanvasTab(Canvas canvas){
this.canvas = canvas;
}