title: Add scroll-lock button to JScrollBar
body: <h1>Background</h1>
  <p>Looking to add a scroll-lock button to the corner of <code>JScrollPane</code> without obscuring the view port contents. The following image shows a <code>JScrollPane</code> wrapped in a <code>SwingNode</code> within a JavaFX application:</p>
  <p><a href="https://i.stack.imgur.com/GpTkq.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/GpTkq.png" alt="Actual" /></a></p>
  <p>The lower-right corner shows a button with a lock icon that may be toggled, which is the desired result:</p>
  <p><a href="https://i.stack.imgur.com/BnDUI.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/BnDUI.png" alt="Final" /></a></p>
  <p>Notice how the content at the very bottom of the view port---the portion beside the lock button---is visible. (Clicking the button will simulate pressing the scroll-lock button on the keyboard. Having a scroll-lock button at the top is perfectly fine, if that's any easier.)</p>
  <h1>Problem</h1>
  <p>The <a href="https://docs.oracle.com/en/java/javase/11/docs/api/java.desktop/javax/swing/JScrollPane.html" rel="nofollow noreferrer">JScrollPane</a> API shows the following image:</p>
  <p><a href="https://i.stack.imgur.com/LGKXl.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/LGKXl.gif" alt="JScrollPane" /></a></p>
  <p>Enabling the corner component also seems to require adding a column header. The addition of the header obscures part of the view port, in direct proportion to the scroll-lock button height. Here's a screenshot showing the visible column header, which hides part of the document:</p>
  <p><a href="https://i.stack.imgur.com/whwYN.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/whwYN.png" alt="Obscured output" /></a></p>
  <h1>Ideas</h1>
  <p>I've tried making the header view panel transparent, to no avail.</p>
  <h1>Code</h1>
  <p>The relevant code within the <code>SwingNode</code>:</p>
  <pre class="lang-java prettyprint-override"><code>// FlyingSaucer subclass
  mView = new HtmlPanel(); 
  mScrollPane = new JScrollPane( mView );
  setContent( mScrollPane );
  
  final var lock = new JButton( &quot;X&quot; );
  mScrollPane.setCorner( UPPER_TRAILING_CORNER, lock );
  mScrollPane.setVerticalScrollBarPolicy( VERTICAL_SCROLLBAR_ALWAYS );
  
  final var header = new JPanel();
  header.setPreferredSize(
    new Dimension( 12, lock.getPreferredSize().height ) );
  header.setOpaque( false );
  header.setBackground( new Color( 0, 0, 0, 0 ) );
  mScrollPane.setColumnHeaderView( header );
  </code></pre>
  <p>See <a href="https://stackoverflow.com/a/17091949/59087">camickr's answer</a> for another example.</p>
  <h1>Question</h1>
  <p>How would you add a button to <code>JScrollPane</code>'s bottom (or top) corner such that no view port content is obscured?</p>
  <h1>Related</h1>
  <ul>
  <li><a href="https://stackoverflow.com/q/17088671/59087">How to make a corner component always visible in a JScrollPane</a></li>
  </ul>