java - How to draw on JPanel on fixed position? -


I have JPanel wrapped in JScrollPane and I want to draw the rectangle to the same position = Will not have the effect of moving with the scrollbar. Rectangular visibility

I tried the following code:

  Public Zero Color Company (Graphics G) {g.setColor (Color.red); G.drawRect (50, (int) getVisibleRect (). GetY (), 20, 20); }  

But this only translates the rectangle when the size of the whole JPNL changes.

Comments