Reputation: 1
I have a canvas that is drawing everything in a paintComponent()
method.
Is it possible to draw outside of paintComponent
(without calling a method within paintComponent
?)
If so how do you go about doing this?
Upvotes: 0
Views: 1360
Reputation: 1
I found out how to solve this issue.
What I did was make JPanel an inner class to my JFrame class.
In JPanels paintComponent I had it calling a method from the outer class which did some updating of the graphics, by passing paintComponents Graphics2D object.
This has allowed me to paint "outside" of paintComponent, just as I needed.
Upvotes: -1
Reputation: 168835
It depends what you mean and why you need it. For example, it is possible to create a BufferedImage
, get the Graphics2D
object, Graphics.paint()
everything that should be on the image, then drop the image into a JLabel
.
But since I do not know what you are trying to achieve (as opposed to what you are trying to do) I cannot know if that answer solves the unstated problem.
Upvotes: 2