Displaying HTML in JFrame

I’d like to get some HTML from a page and display it instead of writing my own parsing and trying to display it all with text();

I’ve cobbled this together from examples I’ve found on the old forum and stackoverflow, but it currently just displays a blank window.

Is this possible?

import javax.swing.*;
import java.net.*;
import processing.awt.PSurfaceAWT;
import javax.swing.JFrame;

String site = "https://processing.org/overview/";

void setup() {
  JTextPane tp = new JTextPane();
  JScrollPane js = new JScrollPane();
  js.getViewport().add(tp);

  JFrame jf = getJFrame();
  jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  jf.getContentPane().add(js);
  jf.pack();
  jf.setSize(400, 500);
  jf.setVisible(true); 
  try {
    URL url = new URL(site);
    tp.setPage(url);
  } 
  catch (Exception e) {
    e.printStackTrace();
  }
}

JFrame getJFrame() {
  PSurfaceAWT surf = (PSurfaceAWT) getSurface();
  PSurfaceAWT.SmoothCanvas canvas = (PSurfaceAWT.SmoothCanvas) surf.getNative();
  return (JFrame) canvas.getFrame();
}

If it’s possible I’ve got no idea how to add components to the Processing’s own canvas. :expressionless:

What I always do is to create my own JFrame, like I did in this sketch link: :framed_picture:

1 Like