开发者

How to paint outside of 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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜