0

I have a Java Swing application with lots of custom components. The layout is a large JScrollPane that contains a JPanel, which has several panels in a BoxLayout from left to right.

In the image below, the code panel contains a JScrollPane that contains another panel that draws its text. This is all custom, no JTextArea/JTextView/Whatever.

I'm stumped by the effect I'm getting below. It seems as though whatever "tween" is being drawn on is either not opaque, or isn't being re-drawn at the right time. I've tried everything I can, but had no luck fixing things. The code drawing the text is very simple - uses Graphics2D and g2.drawString(...).

enter image description here

alistair
  • 1,164
  • 10
  • 27

1 Answers1

1

The JComponent API notes that, "If you do not honor the opaque property you will likely see visual artifacts." A typical example that violates this principle is examined here. The effect usually stems from displaying a buffered remnant that you've told Swing should not need repainting. In particular,

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.

Community
  • 1
  • 1
trashgod
  • 203,806
  • 29
  • 246
  • 1,045