PawelW PawelW - 1 year ago 97
Java Question

JavaFX I can't draw anything on canvas created in Scene Builder

I created scene in SceneBuilder which included canvas object. Now I'm trying to draw anything on canvas, but nothing appear. Maybe someone could tell me what I'm doing wrong. Thanks in advice.

Here is declaration of canvas object:

public class ApplicationControler implements Initializable {

public Canvas artHorizon;

And the method which should draw something on it:

public void drawOval(){
artHorizon = new Canvas(400, 400);
GraphicsContext gc = artHorizon.getGraphicsContext2D();

gc.fillOval(110, 30, 50, 50);

And the Main class:

public class Main extends Application {

public void start(Stage stage) throws Exception {

FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/application/MainPane.fxml"));
Parent parent = fxmlLoader.load();
Scene scene = new Scene(parent);

stage.setTitle("Login Page");;

ApplicationControler controller = fxmlLoader.getController();


public static void main(String[] args) {


Answer Source

I think you should remove:

artHorizon = new Canvas(400, 400);

See if you can do something like this:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download