开发者

How to paint outside of paintComponent?

开发者 https://www.devze.com 2023-03-03 13:03 出处:网络
I have a开发者_Go百科 canvas that is drawing everything in a paintComponent() method. Is it possible to draw outside of paintComponent (without calling a method within paintComponent?)

I have a开发者_Go百科 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?


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号