java - JavaFX Canvas - how to repaint a canvas after painting? -
i wrote code possible paint on javafx canvas. works fine don't know how repaint (like in swing) canvas start again painting on new canvas. here code , lot help! mario
public class main extends application { private static final int width = 600; private static final int heigth = 400; @override public void start(stage primarystage) { //handling canvas final canvas canvas = new canvas(width, heigth); final graphicscontext gc = canvas.getgraphicscontext2d(); gc.setfill(color.aqua); gc.fill(); //painting mousedragged event canvas.setonmousedragged(event -> gc.filloval(event.getx(), event.gety(), 25, 25)); //user colorpicke color of painting colorpicker cp = new colorpicker(); cp.setonaction(e -> gc.setfill(cp.getvalue())); //layout borderpane root = new borderpane(); hbox hb = new hbox(30); button button = new button("clear all"); button.setonaction(e -> /*how repaint canvas*/ system.out.println("how repaint???")); hb.getchildren().addall(cp, button); hb.setprefheight(200); hb.setalignment(pos.center); root.setcenter(canvas); root.setbottom(hb); final scene scene = new scene(root); primarystage.settitle("hello world!"); primarystage.setscene(scene); primarystage.show(); } public static void main(string[] args) { launch(args); } }
by clearing canvas :
button.setonaction(e -> gc.clearrect(0, 0, canvas.getwidth(), canvas.getheight()));
Comments
Post a Comment