我实现了缩小字段(Canvas)的功能,点击按钮.原则上,一切都正常工作,但是当你缩小时,白色区域会出现在画布所在的滚动窗格中.
我try 的所有选项都在代码中提供. 有没有可能使滚动窗格的内部区域根据画布的大小而改变,并go 除白色区域?
public class GameView {
@FXML public Canvas gameField;
@FXML public ScrollPane scrollPane;
public void doZoomOut() {
Scale scale = new Scale(gameField.getScaleX() * 0.8, gameField.getScaleY() * 0.8);
gameField.getTransforms().add(scale);
scrollPane.resize(gameField.getWidth(), gameField.getHeight()); //doesn't work
scrollPane.setPrefViewportWidth(gameField.getWidth()); //doesn't work
scrollPane.setPrefViewportHeight(gameField.getHeight()); //doesn't work
//Fit to Width/Height also doesn't work
scrollPane.setPrefWidth(gameField.getWidth()); //doesn't work
}
}
<ScrollPane fx:id="scrollPane" fitToHeight="true" fitToWidth="true" style="-fx-background-color: transparent;" stylesheets="@../../../style.css">
<styleClass>
<String fx:value="scroll-bar" />
<String fx:value="corner" />
<String fx:value="thumb" />
</styleClass>
<Canvas fx:id="gameField" height="700.0" width="1200.0" />
</ScrollPane>