java - Swing JScrollPane 溢出

标签 java swing graphics2d

我有一个包含许多自定义组件的 Java Swing 应用程序。布局是一个大的 JScrollPane,其中包含一个 JPanel,它在 BoxLayout 中从左到右有多个面板。

在下图中,代码面板包含一个 JScrollPane,其中包含另一个绘制文本的面板。这都是自定义的,没有 JTextArea/JTextView/Whatever。

我对下面的效果感到困惑。似乎所绘制的“补间”要么不是不透明的,要么没有在正确的时间重新绘制。我已尽我所能,但没能解决问题。绘制文本的代码非常简单 - 使用 Graphics2D 和 g2.drawString(...)。

enter image description here

最佳答案

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/

相关文章:

java - GridBagLayout 中的 JTextField ActionListener

java - 卡住 Java JComponent

java - 在玩家身后创建一条血迹

java - 如何使 java 应用程序与 ESP32 板通信?

java - org.json.JSONObject.getLong 给出不精确的结果

java - 在 SwingWorker 中调用 super.approveSelection()

java - 在 JFrame 中向下移动一个矩形

java - 无法导入 ClassPathXmlApplicationContext

java - 从数据包 header 设置 Java 字节数组大小

java - 如何使用 AffineTransform.quadrantRotate 旋转位图?