3

I'm trying to use a JScrollPane with a column header and a row header.

On the rowheader, there is some text. When I scroll down the pane, some graphics artifacts appear on the rowheader. It's like the bottom line of pixels is repeated once and again.

The problem is solved if I maximize and restore the main window, but it's not the way it should be.

Is there any way to avoid this?

aymeric
  • 3,877
  • 2
  • 28
  • 42
javier
  • 133
  • 1
  • 2
  • 5
  • 5
    The problem is with the custom painting code of your row header. Post your [SSCCE](http://sscce.org) that demonstrates the problem. – camickr Aug 09 '11 at 16:00
  • 3
    A guess: if you do custom painting in the row header, do you call the super method in the paint method? In other words, if you override paint, do you call `super.paint(g)`? and likewise for paintComponent/super.paintComponent. And I agree with camickr, please show us an SSCCE if this doesn't help. – Hovercraft Full Of Eels Aug 09 '11 at 16:44
  • Thanks. You are right. There was something in the custom paint code. I fixed it adding a line setting the preferred size of the component. – javier Aug 09 '11 at 17:52

1 Answers1

0

I find that glitches like this are usually caused by custom paint() methods or not repainting after you make changes.

First, I always call as the first line in my custom paint method.

super.paint();  or  super.paintComponent(g);

I also find that these two lines keep everything fresh and up to date. They might be time consuming, but they have solved a lot of problems. I usually put them at the end of code that modifies the view.

this.validate();
this.repaint();
kevin_s
  • 41
  • 1
  • 2
    doctoring on symptons by random method calling is _not_ recommended - instead, find the error and fix it – kleopatra Sep 25 '12 at 15:19