简体   繁体   English

在JFrame的玻璃窗格上使用paintComponent(Graphics g)

[英]Using paintComponent(Graphics g) on JFrame's glass pane

I am trying to draw on the glass pane part of a JFrame with a marker using g.fillPolygon(xValues, yValues, numPoints) after making the background of the JFrame transparent. 我试图在使JFrame的背景透明之后g.fillPolygon(xValues, yValues, numPoints)使用g.fillPolygon(xValues, yValues, numPoints)用标记在JFrame的玻璃窗格部分上绘制。

I am using a method to find the location of the cursor and can get the right locations. 我正在使用一种方法来找到光标的位置,并可以获得正确的位置。 To force the call of paintComponent(Graphics g) , I am using myGlassPane.repaint() but this deletes the previous part of the segment that I drew. 为了强制调用paintComponent(Graphics g) ,我正在使用myGlassPane.repaint()但这会删除我绘制的线段的前一部分。

I am wondering if there is a way to retain what was previously drawn through the paintComponent(Graphics g) method. 我想知道是否有办法保留以前通过paintComponent(Graphics g)方法绘制的内容。

I am wondering if there is a way to retain what was previously drawn through the paintComponent(Graphics g) method. 我想知道是否有办法保留以前通过paintComponent(Graphics g)方法绘制的内容。

Yes, add whatever you drew before either to a BufferedImage or a List which can allow you to create it... 是的,将您之前绘制的内容添加到BufferedImageList ,可以让您创建它...

For example 例如

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM