In javaFX to resize a canvas there is no such method to do that, the only solution is to extends from Canvas.
class ResizableCanvas extends Canvas {
pub
The canvas class just needs to override isResizable() (everything else, which is suggested in other examples, is actually not necessary) :
public class ResizableCanvas extends Canvas
{
public boolean isResizable()
{
return true;
}
}
And in the Application the width and height properties of the canvas have to be bound to the canvas' parent:
@Override
public void start(Stage primaryStage) throws Exception
{
...
StackPane pane = new StackPane();
ResizableCanvas canvas = new ResizableCanvas(width, height);
canvas.widthProperty().bind(pane.widthProperty());
canvas.heightProperty().bind(pane.heightProperty());
pane.getChildren().add(_canvas);
...
}
Listeners can be added to the width in height properties, in order to redraw the canvas, when it is resized (but if you need that and where to place it, depends on your application):
widthProperty().addListener(this::paint);
heightProperty().addListener(this::paint);