Of all the methods shown, this was the only method that really allowed you to resize the canvas:
public class ResizableCanvas extends Canvas { @Override public boolean isResizable() { return true; } @Override public double maxHeight(double width) { return Double.POSITIVE_INFINITY; } @Override public double maxWidth(double height) { return Double.POSITIVE_INFINITY; } @Override public double minWidth(double height) { return 1D; } @Override public double minHeight(double width) { return 1D; } @Override public void resize(double width, double height) { this.setWidth(width); this.setHeight(height) } }
I did not want to break encapsulation by forcing the parent component to send us width and height ; I also did not want to make the canvas the only child in it, occupying all the space; and finally, a canvas was drawn in another class, so the drawing method did not live inside the canvas.
With this canvas, I donβt need to bind its parent width / height properties to resize the canvas. It simply resizes with any size selected by the parent. In addition, anyone using a canvas can simply bind its width / height properties and control their own drawing when these properties change.
smac89
source share