How to make canvas with Swing?

In order to make a custom ‘Canvas’ in swing you usually write a subclass of a JPanel. Then, you must overwrite the protected paintComponent(Graphics g) method of JPanel.

In the paint method, you can call methods on the Graphics object to actually draw on the JPanel.

As always, the Java Tutorials have a great reference on this to get you started.

Leave a Comment