Suppose I have big custom control inscribed inside JScrollPane
or clipped by other reasons. How to determine from within paintComponent()
method which coordinates are to paint?
Asked
Active
Viewed 742 times
1

Suzan Cioc
- 29,281
- 63
- 213
- 385
2 Answers
4
Take a look at Painting in AWT and Swing, it has an excellent explanation.
But the general gist is, when your component is painted, its clipping rectangle is already set (nb need to check how this works for view ports, but I suspect its the same) to the visible area needing to be updated.
You can check the clip rectangle of the Graphics context past to your paint method and determine what area you should update.

MadProgrammer
- 343,457
- 22
- 230
- 366
-
[for example](http://stackoverflow.com/a/11330436/714968), then I'm not sure if is there only visible rectangle painted (by default) – mKorbel Feb 13 '13 at 21:54
2
You can find out the JScrollPane viewport with
jScrollPane.getViewport()
once there you can know the rectangle shown by the JScrollPane with
jScrollPane.getViewport().getViewRect()
so the you can you that Rectangle to paint your custom component
Regards

ultraklon
- 590
- 4
- 9