title: JavaFX SimpleSwingBrowser auto fit web page
body: <p>In order to support oAuth 2 in my Swing application, I need to load a web page URL supplied by Google. Since JavaFX has a better web support, I decide to use the source code from <a href="http://docs.oracle.com/javafx/2/swing/SimpleSwingBrowser.java.htm" rel="nofollow noreferrer">http://docs.oracle.com/javafx/2/swing/SimpleSwingBrowser.java.htm</a></p>
  
  <pre><code>SwingUtilities.invokeLater(new Runnable() {
  
      public void run() {
          SimpleSwingBrowser browser = new SimpleSwingBrowser();
          browser.setVisible(true);
          browser.loadURL(googleUrl);
      }     
  });
  </code></pre>
  
  <p>Since the code example provided by Oracle doesn't come with "auto-fit web page" feature, I will be getting a display something like</p>
  
  <p><img src="https://i.stack.imgur.com/GWb5j.png" alt="enter image description here"></p>
  
  <p>The closest example is <a href="http://java-no-makanaikata.blogspot.com/2012/10/javafx-webview-size-trick.html" rel="nofollow noreferrer">http://java-no-makanaikata.blogspot.com/2012/10/javafx-webview-size-trick.html</a>. However, the example requires us to inject our custom <code>&lt;div&gt;</code> tag into <code>WebView</code>'s content, which is not something I wish to do. I prefer to HTML content loading, all done by `WebView.</p>