How to draw on JPanel on fixed position?

Posted by kovike on Stack Overflow See other posts from Stack Overflow or by kovike
Published on 2010-05-17T02:04:33Z Indexed on 2010/05/17 2:10 UTC
Read the original article Hit count: 274

Filed under:
|
|

I have JPanel wrapped in JScrollPane and I want the rectangle to be drawn always on the same position = moving with scrollbars wont affect the visibility of the rectangle.

I tried following code:

    public void paintComponent(Graphics g) {
        g.setColor(Color.red);
        g.drawRect(50, (int)getVisibleRect().getY(), 20 , 20);
    }

but it only repaints the rectangle when size of whole JPanel is changed.

© Stack Overflow or respective owner

Related posts about java

Related posts about jpanel