Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I was able to reproduce your problem and get you the result your looking for. The problem is that the drawing of the image wasn't complete by the time you were repainting again, so only portions of the image were being painted. To fix this, add this field to your <code>JScrollNavigator</code> class (as a lock):</p> <pre><code>/** Lock to prevent trying to repaint too many times */ private boolean blockRepaint = false; </code></pre> <p>When we repaint the component, this lock will be activated. It won't be released until we have been able to successfully paint the panel - then another paint can be executed.</p> <p>The <code>paintComponent</code> needs to be changed to abide by the lock and use a <code>ImageObserver</code> when painting your navigation panel.</p> <pre><code>@Override protected void paintComponent(final Graphics g) { super.paintComponent(g); if(!blockRepaint){ final Component view = (Component)jScrollPane.getViewport().getView(); BufferedImage img = new BufferedImage(view.getWidth(), view.getHeight(), BufferedImage.TYPE_INT_ARGB); Graphics2D g2d = img.createGraphics(); g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); // Paint JScrollPane view to off-screen image and then scale. // It is this action that causes the display corruption! view.paint(g2d); ImageObserver io = new ImageObserver() { @Override public boolean imageUpdate(Image img, int infoflags, int x, int y,int width, int height) { boolean result = true; g.drawImage(img, 0, 0, null); if((infoflags &amp; ImageObserver.FRAMEBITS) == ImageObserver.FRAMEBITS){ blockRepaint = false; result = false; } return result; } }; Image scaled = img.getScaledInstance(getWidth(), getHeight(), 0); blockRepaint = g.drawImage(scaled, 0, 0, io); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

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