强制的JPanel的Java2D完全重绘 [英] Force full redraw of a Jpanel Java2D

查看:492
本文介绍了强制的JPanel的Java2D完全重绘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是,我需要做出不断更新becuse我得到,可以从一个数据库更改值和我得到了在图形领域的一些问题的GUI。

My question is that i need to make a GUI that keeps updating becuse i get values that can change from a DB and i got some problems in the graphical area.

以及即时通讯使用的drawLine和束带从Graphics2D的属于该数据库上找到打印的数值,这个字符串和线移动和变化值,所以我需要调用重绘();用一个计时器,使它们在在JPanel冲击片雷管,问题是,重绘();画中的背景前没有删除旧的画,但是当我调整所有更新perfecly。

well im using Drawline and Drawstring from Graphics2D that print values that are found on the database, this strings and lines move and change value, so i need to call repaint(); with a timer to make them apper in the jpanel, the problem is that repaint(); is not removing the old painting in the background before painting, but when i resize all updates perfecly.

我知道一种方法来清除,但背景颜色消失得如此,
有一种方法来更新的JPanel删除旧的画作​​,并保持deafult背景颜色?

i know a way to clear but the background color goes away too so, There is a way to update the jpanel removing old paintings and keep the deafult background color?

未更新

Not updated

改变coordenate和标签的文字为轴Y后(重绘自动定时调用)

After changing a coordenate and a label text to "AXIS Y" (repaint called automatically from a timer)

感谢。

推荐答案

从图像的外观上来看,它看起来像你只是忘记叫 super.paintComponent方法的paintComponent 方法。这样做是重新绘制背景给你,所以不会留下与previous油漆文物。

From the looks of your image, it looks like you're just forgetting to call super.paintComponent in the paintComponent method. What this does is repaint the background for you, so aren't left with the previous paint artifacts.

@Override
protected voud paintComponent(Graphics g) {
    super.paintComponent(g);
}

请注意:为了未来的参考,虽然图像给了我们一个很好的图片,它总是最好张贴一个最小的,完整的可验证的例子随着这些图像,所以我们的的已经进行猜测(学历与否)

Note: For future reference, though the images gave us a good picture, it always best to post a Minimal, Complete, and Verifiable example along with those images, so we don't have to make guesses (educated or not)

这篇关于强制的JPanel的Java2D完全重绘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆