工具提示消失后如何重新绘制?

发布于 2024-11-01 19:17:16 字数 355 浏览 0 评论 0原文

我创建了一个小程序,它有一个大面板来显示由多个控件(按钮、文本字段等)包围的数据。大面板包含我自己渲染的几层标签。

所有控件都有与之关联的工具提示,其中一些工具提示与主面板重叠。当它们消失时,它们会在主面板图像中留下一个洞,直到重新绘制主面板。

现在请注意,这种情况并不总是发生。仅当光标位于特定范围内时才会发生。如果向左或向右移动得足够远(沿 Y 轴的变化没有注意到差异),则当工具提示消失时,孔会被覆盖。

我不太熟悉工具提示和重绘应该如何工作,如果这表明我的程序有严重错误,但如果我可以在工具提示消失时在主面板上调用重绘,我应该没事。我可以在工具提示中重写某些内容来实现此目的吗?

我正在使用 Swing

谢谢。

I've created an applet which has one large panel to display data surrounded by several controls (buttons, textfields, etc.). The large panel contains several layers of labels which I render myself.

The controls all have tooltips associated with them, and some of these tooltips overlap the main panel. When they disappear, they leave a hole in the main panel image until the main panel is repainted.

Now mind you, this does not always happen. It only occurs when the cursor is in a certain range. If you get far enough to either the left or right (no difference noted for changes along the Y axis), the holes are painted over when the tooltip disappears.

I'm not well-versed on how tooltips and repainting are supposed to work, and if this is a sign that there's something dreadfully wrong with my program, but if I can just call repaint on the main panel whenever the tooltip disappears, I should be fine. Is there something I can override in tooltip to make this happen?

I'm using Swing

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

疧_╮線 2024-11-08 19:17:16

回答你的问题(在你通过评论找到解决方案之后): Swing 内置了一些相当复杂的重绘管理。当工具提示消失时,它下面的矩形将被重绘。

现在,哪些组件必须重新喷漆?所有与给定矩形重叠的组件,并且它们本身没有被其他组件隐藏(在相关区域中) - 但这里只计算不透明组件。 (这就是我们需要 JComponent 上的 opaque 属性的全部原因 - 以优化重新绘制。)

您的标签声明自己是不透明的,但并没有真正在 paintComponent,这样应该被标签覆盖的工具提示区域就保持未绘制状态。

声明标签部分透明也会导致其后面组件的相关区域被重新绘制。

To answer your question (after you found a solution by the comments): Swing has some quite elaborate repaint management built in. When a tooltip disappears, the rectangle below it is repainted.

Now, which components have to be repainted? All those who overlap with the given rectangle, and are not themselves hidden (in the region in question) by other components - but only opaque components count here. (This is the whole reason we need the opaque property on JComponent - to optimize repainting.)

Your label declared itself being opaque, but did not really paint its whole area on a paintComponent, and such the region of the tooltip which should have been covered by the label stayed unpainted.

Declaring your label to be partly transparent caused also the concerning region of the component behind it to be repainted.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文