Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Summary: The original <a href="http://www.javalobby.org/java/forums/t21355.html" rel="nofollow noreferrer"><code>JScrollNavigator</code></a> uses the Swing <a href="http://java.sun.com/products/jfc/tsc/articles/painting/index.html#props" rel="nofollow noreferrer"><code>opacity</code></a> property to render a convenient green <code>NavBox</code> over a scaled thumbnail of the component in an adjacent <code>JScrollPane</code>. Because it extends <code>JPanel</code>, the (shared) UI delegate's use of <code>opacity</code> conflicts with that of the scrollable component. The images seen in edit 5 above typify the associated rendering artifact, also shown <a href="https://stackoverflow.com/q/7213178/230513">here</a>. The solution is to let <code>NavBox</code>, <code>JScrollNavigator</code> and the scrollable component extend <code>JComponent</code>, as suggested in the second addendum below. Each component can then manage it's own properties individually.</p> <p><img src="https://i.stack.imgur.com/TpGg0.png" alt="enter image description here"></p> <p>I see no unusual rendering artifact with your <a href="http://wklej.to/RnkO1" rel="nofollow noreferrer">code as posted</a> on my platform, Mac OS X, Java 1.6. Sorry, I don't see any glaring portability violations.</p> <p><img src="https://i.stack.imgur.com/wlCUQ.png" alt="image one"></p> <p>A few probably irrelevant, but perhaps useful, observations.</p> <ul> <li><p>Even if you use <code>setSize()</code>, appropriately in this case, you should still <code>pack()</code> the enclosing <code>Window</code>.</p> <pre><code>f.pack(); f.setSize(300, 200); </code></pre></li> <li><p>For convenience, <code>add()</code> forwards the component to the content pane.</p> <pre><code>f.add(nav, BorderLayout.WEST); </code></pre></li> <li><p>Prefer <code>StringBuilder</code> to <code>StringBuffer</code>.</p></li> <li><p>Consider <code>ComponentAdapter</code> in place of <code>ComponentListener</code>.</p></li> </ul> <p>Addendum: As suggested <a href="https://stackoverflow.com/a/6916719/230513">here</a>, I got somewhat more flexible results using <code>RenderingHints</code> instead of <code>getScaledInstance()</code> as shown below. Adding a few icons makes it easier to see the disparate effect on images and text.</p> <p><img src="https://i.stack.imgur.com/P0QIy.png" alt="image two"></p> <pre><code>editPane.insertIcon(UIManager.getIcon("OptionPane.errorIcon")); editPane.insertIcon(UIManager.getIcon("OptionPane.warningIcon")); ... @Override protected void paintComponent(Graphics g) { super.paintComponent(g); Component view = jScrollPane.getViewport().getView(); BufferedImage img = new BufferedImage(view.getWidth(), view.getHeight(), BufferedImage.TYPE_INT_ARGB); Graphics2D off = img.createGraphics(); off.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); off.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); view.paint(off); Graphics2D on = (Graphics2D)g; on.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); on.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC); on.drawImage(img, 0, 0, getWidth(), getHeight(), null); } </code></pre> <p>Addendum secundum: It looks like the <code>JPanel</code> UI delegate is not cooperating. One workaround is to extend <code>JComponent</code> so that you can control <a href="http://java.sun.com/products/jfc/tsc/articles/painting/index.html#props" rel="nofollow noreferrer">opacity</a>. It's only slightly more work to manage the <code>backgroundColor</code>. <code>NavBox</code> and <code>JScrollNavigator</code> are also candidates for a similar treatment.</p> <p><img src="https://i.stack.imgur.com/k5oiz.png" alt="enter image description here"></p> <pre><code>jsp.setViewportView(new JComponent() { { setBackground(Color.red); setBorder(BorderFactory.createLineBorder(Color.BLACK, 16)); } @Override protected void paintComponent(Graphics g) { super.paintComponent(g); g.setColor(getBackground()); g.fillRect(0, 0, getWidth(), getHeight()); } @Override public Dimension getPreferredSize() { return new Dimension(300, 300); } }); </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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. 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