我有一个包含许多自定义组件的 Java Swing 应用程序。布局是一个大的 JScrollPane,其中包含一个 JPanel,它在 BoxLayout 中从左到右有多个面板。
在下图中,代码面板包含一个 JScrollPane,其中包含另一个绘制文本的面板。这都是自定义的,没有 JTextArea/JTextView/Whatever。
我对下面的效果感到困惑。似乎所绘制的“补间”要么不是不透明的,要么没有在正确的时间重新绘制。我已尽我所能,但没能解决问题。绘制文本的代码非常简单 - 使用 Graphics2D 和 g2.drawString(...)。
最佳答案
JComponent
API 指出,“如果您不遵守opaque property,您可能会看到视觉伪影。”考察一个违反这一原则的典型例子here 。该效果通常源于显示您告诉 Swing 不需要重新绘制的缓冲残余。特别是,
One of the most common mistakes component implementations make is that they allow the opaque property to default to
true
, yet they do not completely render the area defined by their bounds, the result is occasional screen garbage in the unrendered areas.
关于java - Swing JScrollPane 溢出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19811461/