Note that there are some explanatory texts on larger screens.

plurals
  1. POJava: Am I responsible for only painting the visible region of (JScrollPane) Viewport View?
    text
    copied!<p>I'm using the Java Tutorials example of how to use a JScrollPane (with row/column headers). The example is using a subclass of JLabel to display an image in the Viewport View. I used the sample code for displaying the row/column headers (<a href="http://docs.oracle.com/javase/tutorial/displayCode.html?code=http://docs.oracle.com/javase/tutorial/uiswing/examples/components/ScrollDemoProject/src/components/Rule.java" rel="nofollow" title="Rule.java">Rule.java example code</a>) and was perplexed at the bizarre results. I finally removed the call to getClipBounds() (apparently used to determine what region of the row/column header is visible to paint only that region) and painted the entire header, and the problem was resolved. That means that I'm now drawing the entire area (in both the row/column headers and the main Viewport). That strikes me as non-optimal.</p> <ol> <li>Can anyone explain why the Java Tutorials example works properly (other than the source is not the same as that being executed in the example)?</li> <li>Is it correct for me to be painting the entire pane even though it is only partially visible?</li> <li>How can I determine what region of the overall object is visible in the Viewport (for row/column headers and the main Viewport) so I can just paint that region?</li> </ol> <p><strong>UPDATE:</strong></p> <p>I still don't know why the example works, but I've found that if I use JComponent.getVisibleRect() instead of Graphics.getClipBounds() things seem to work as expected. Not sure if this is the correct use of this method.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload